|
|
@ -28,30 +28,31 @@ import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOF
|
|
|
|
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOUtil;
|
|
|
|
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOUtil;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.*;
|
|
|
|
import java.io.*;
|
|
|
|
import java.sql.Connection;
|
|
|
|
import java.sql.*;
|
|
|
|
import java.sql.PreparedStatement;
|
|
|
|
|
|
|
|
import java.sql.ResultSet;
|
|
|
|
|
|
|
|
import java.sql.SQLException;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class ProfileOperationDAOImpl extends OperationDAOImpl {
|
|
|
|
public class ProfileOperationDAOImpl extends OperationDAOImpl {
|
|
|
|
|
|
|
|
|
|
|
|
private static final Log log = LogFactory.getLog(ProfileOperationDAOImpl.class);
|
|
|
|
private static final Log log = LogFactory.getLog(ProfileOperationDAOImpl.class);
|
|
|
|
|
|
|
|
|
|
|
|
public int addOperation(Operation operation) throws OperationManagementDAOException {
|
|
|
|
public int addOperation(Operation operation) throws OperationManagementDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
int operationId = super.addOperation(operation);
|
|
|
|
int operationId = super.addOperation(operation);
|
|
|
|
|
|
|
|
operation.setCreatedTimeStamp(new Timestamp(new java.util.Date().getTime()).toString());
|
|
|
|
|
|
|
|
operation.setId(operationId);
|
|
|
|
ProfileOperation profileOp = (ProfileOperation) operation;
|
|
|
|
ProfileOperation profileOp = (ProfileOperation) operation;
|
|
|
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
|
|
|
Connection conn = OperationManagementDAOFactory.openConnection();
|
|
|
|
|
|
|
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
|
|
|
|
ByteArrayOutputStream bao = null;
|
|
|
|
ByteArrayOutputStream bao = null;
|
|
|
|
ObjectOutputStream oos = null;
|
|
|
|
ObjectOutputStream oos = null;
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
bao = new ByteArrayOutputStream();
|
|
|
|
bao = new ByteArrayOutputStream();
|
|
|
|
oos = new ObjectOutputStream(bao);
|
|
|
|
oos = new ObjectOutputStream(bao);
|
|
|
|
oos.writeObject(profileOp);
|
|
|
|
oos.writeObject(profileOp);
|
|
|
|
|
|
|
|
|
|
|
|
stmt = conn.prepareStatement("INSERT INTO DM_PROFILE_OPERATION(OPERATION_ID, PAYLOAD) VALUES(?, ?)");
|
|
|
|
stmt = conn.prepareStatement("INSERT INTO DM_PROFILE_OPERATION(OPERATION_ID, OPERATIONDETAILS) " +
|
|
|
|
|
|
|
|
"VALUES(?, ?)");
|
|
|
|
stmt.setInt(1, operationId);
|
|
|
|
stmt.setInt(1, operationId);
|
|
|
|
stmt.setBytes(2, bao.toByteArray());
|
|
|
|
stmt.setBytes(2, bao.toByteArray());
|
|
|
|
stmt.executeUpdate();
|
|
|
|
stmt.executeUpdate();
|
|
|
@ -74,29 +75,29 @@ public class ProfileOperationDAOImpl extends OperationDAOImpl {
|
|
|
|
log.warn("Error occurred while closing ObjectOutputStream", e);
|
|
|
|
log.warn("Error occurred while closing ObjectOutputStream", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
OperationManagementDAOUtil.cleanupResources(stmt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return operationId;
|
|
|
|
return operationId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Operation getOperation(int operationId) throws OperationManagementDAOException {
|
|
|
|
public Operation getOperation(int operationId) throws OperationManagementDAOException {
|
|
|
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
|
|
|
Connection conn = OperationManagementDAOFactory.openConnection();
|
|
|
|
|
|
|
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
ByteArrayInputStream bais = null;
|
|
|
|
ByteArrayInputStream bais = null;
|
|
|
|
ObjectInputStream ois = null;
|
|
|
|
ObjectInputStream ois = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
stmt = conn.prepareStatement("SELECT PAYLOAD FROM DM_PROFILE_OPERATION WHERE ID = ?");
|
|
|
|
stmt = conn.prepareStatement("SELECT OPERATIONDETAILS FROM DM_PROFILE_OPERATION WHERE OPERATION_ID = ?");
|
|
|
|
stmt.setInt(1, operationId);
|
|
|
|
stmt.setInt(1, operationId);
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
|
|
|
|
|
|
|
|
byte[] payload = new byte[0];
|
|
|
|
byte[] operationDetails = new byte[0];
|
|
|
|
if (rs.next()) {
|
|
|
|
if (rs.next()) {
|
|
|
|
payload = rs.getBytes("PAYLOAD");
|
|
|
|
operationDetails = rs.getBytes("OPERATIONDETAILS");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bais = new ByteArrayInputStream(payload);
|
|
|
|
bais = new ByteArrayInputStream(operationDetails);
|
|
|
|
ois = new ObjectInputStream(bais);
|
|
|
|
ois = new ObjectInputStream(bais);
|
|
|
|
return (ProfileOperation) ois.readObject();
|
|
|
|
return (ProfileOperation) ois.readObject();
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
@ -104,7 +105,7 @@ public class ProfileOperationDAOImpl extends OperationDAOImpl {
|
|
|
|
} catch (IOException e) {
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new OperationManagementDAOException("Error occurred while serializing profile operation object", e);
|
|
|
|
throw new OperationManagementDAOException("Error occurred while serializing profile operation object", e);
|
|
|
|
} catch (ClassNotFoundException e) {
|
|
|
|
} catch (ClassNotFoundException e) {
|
|
|
|
throw new OperationManagementDAOException("Error occurred while casting retrieved payload as a " +
|
|
|
|
throw new OperationManagementDAOException("Error occurred while casting retrieved profile operation as a " +
|
|
|
|
"ProfileOperation object", e);
|
|
|
|
"ProfileOperation object", e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
if (bais != null) {
|
|
|
|
if (bais != null) {
|
|
|
@ -122,6 +123,7 @@ public class ProfileOperationDAOImpl extends OperationDAOImpl {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
|
|
|
|
OperationManagementDAOFactory.closeConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -132,51 +134,28 @@ public class ProfileOperationDAOImpl extends OperationDAOImpl {
|
|
|
|
ResultSet rs = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
ByteArrayInputStream bais;
|
|
|
|
ByteArrayInputStream bais;
|
|
|
|
ObjectInputStream ois;
|
|
|
|
ObjectInputStream ois;
|
|
|
|
int operationId = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String operationType = "";
|
|
|
|
|
|
|
|
String createdTime = "";
|
|
|
|
|
|
|
|
String receivedTime = "";
|
|
|
|
|
|
|
|
String operationStatus = "";
|
|
|
|
|
|
|
|
String operationCode = "";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Connection connection = OperationManagementDAOFactory.getConnection();
|
|
|
|
Connection connection = OperationManagementDAOFactory.openConnection();
|
|
|
|
stmt = connection.prepareStatement(
|
|
|
|
stmt = connection.prepareStatement(
|
|
|
|
"SELECT o.ID AS OPERATION_ID, o.CREATED_TIMESTAMP AS CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP AS " +
|
|
|
|
"SELECT po.OPERATIONDETAILS AS OPERATIONDETAILS " +
|
|
|
|
"RECEIVED_TIMESTAMP, po.PAYLOAD AS PAYLOAD,o.TYPE AS TYPE,o.STATUS as STATUS,o.OPERATIONCODE " +
|
|
|
|
|
|
|
|
"FROM DM_OPERATION o " +
|
|
|
|
"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 " +
|
|
|
|
"d.DEVICE_IDENTIFICATION = ?) d1 INNER JOIN DM_DEVICE_OPERATION_MAPPING dom " +
|
|
|
|
"d.DEVICE_IDENTIFICATION = ?) d1 INNER JOIN DM_DEVICE_OPERATION_MAPPING dom " +
|
|
|
|
"ON d1.ID = dom.DEVICE_ID) ORDER BY o.CREATED_TIMESTAMP ASC LIMIT 1;");
|
|
|
|
"ON d1.ID = dom.DEVICE_ID) 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());
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
|
|
|
|
|
|
|
|
byte[] payload = new byte[0];
|
|
|
|
byte[] operationObjbyteArr = new byte[0];
|
|
|
|
if (rs.next()) {
|
|
|
|
if (rs.next()) {
|
|
|
|
operationId = rs.getInt("OPERATION_ID");
|
|
|
|
operationObjbyteArr = rs.getBytes("OPERATIONDETAILS");
|
|
|
|
createdTime = rs.getTimestamp("CREATED_TIMESTAMP").toString();
|
|
|
|
}
|
|
|
|
receivedTime = rs.getTimestamp("RECEIVED_TIMESTAMP").toString();
|
|
|
|
bais = new ByteArrayInputStream(operationObjbyteArr);
|
|
|
|
payload = rs.getBytes("PAYLOAD");
|
|
|
|
|
|
|
|
operationType = rs.getString("TYPE");
|
|
|
|
|
|
|
|
operationStatus = rs.getString("STATUS");
|
|
|
|
|
|
|
|
operationCode = rs.getString("OPERATIONCODE");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bais = new ByteArrayInputStream(payload);
|
|
|
|
|
|
|
|
ois = new ObjectInputStream(bais);
|
|
|
|
ois = new ObjectInputStream(bais);
|
|
|
|
ProfileOperation profileOperation = new ProfileOperation();
|
|
|
|
return (ProfileOperation) ois.readObject();
|
|
|
|
profileOperation.setPayload(ois.readObject());
|
|
|
|
|
|
|
|
profileOperation.setId(operationId);
|
|
|
|
|
|
|
|
profileOperation.setType(Operation.Type.valueOf(operationType));
|
|
|
|
|
|
|
|
profileOperation.setStatus(Operation.Status.valueOf(operationStatus));
|
|
|
|
|
|
|
|
profileOperation.setCreatedTimeStamp(createdTime);
|
|
|
|
|
|
|
|
profileOperation.setReceivedTimeStamp(receivedTime);
|
|
|
|
|
|
|
|
profileOperation.setCode(operationCode);
|
|
|
|
|
|
|
|
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) {
|
|
|
@ -186,6 +165,67 @@ public class ProfileOperationDAOImpl extends OperationDAOImpl {
|
|
|
|
throw new OperationManagementDAOException("Error occurred while serializing profile operation object", e);
|
|
|
|
throw new OperationManagementDAOException("Error occurred while serializing profile operation object", e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
|
|
|
|
OperationManagementDAOFactory.closeConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void updateOperation(Operation operation) throws OperationManagementDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
|
|
|
ByteArrayOutputStream bao = null;
|
|
|
|
|
|
|
|
ObjectOutputStream oos = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
Connection connection = OperationManagementDAOFactory.openConnection();
|
|
|
|
|
|
|
|
stmt = connection.prepareStatement(
|
|
|
|
|
|
|
|
"UPDATE DM_PROFILE_OPERATION O SET O.OPERATIONDETAILS=? WHERE O.OPERATION_ID=?");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bao = new ByteArrayOutputStream();
|
|
|
|
|
|
|
|
oos = new ObjectOutputStream(bao);
|
|
|
|
|
|
|
|
oos.writeObject(operation);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stmt.setBytes(1, bao.toByteArray());
|
|
|
|
|
|
|
|
stmt.setInt(2, operation.getId());
|
|
|
|
|
|
|
|
stmt.executeUpdate();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
|
|
|
throw new OperationManagementDAOException("Error occurred while update operation metadata", e);
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
|
|
|
throw new OperationManagementDAOException("Error occurred while serializing profile operation object", e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
if (bao != null) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
bao.close();
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
|
|
|
log.warn("Error occurred while closing ByteArrayOutputStream", e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (oos != null) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
oos.close();
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
|
|
|
log.warn("Error occurred while closing ObjectOutputStream", e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
OperationManagementDAOUtil.cleanupResources(stmt);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void deleteOperation(int id) throws OperationManagementDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
super.deleteOperation(id);
|
|
|
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
Connection connection = OperationManagementDAOFactory.openConnection();
|
|
|
|
|
|
|
|
stmt = connection.prepareStatement("DELETE DM_PROFILE_OPERATION WHERE OPERATION_ID=?");
|
|
|
|
|
|
|
|
stmt.setInt(1, id);
|
|
|
|
|
|
|
|
stmt.executeUpdate();
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
|
|
|
throw new OperationManagementDAOException("Error occurred while deleting operation metadata", e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
OperationManagementDAOUtil.cleanupResources(stmt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|