Refactored Policy Management DAO classes

revert-70aa11f8
Dileesha Rajapakse 9 years ago
parent 91d9db1ffa
commit 6446be100d

@ -39,6 +39,8 @@ public class PolicyOperationDAOImpl extends OperationDAOImpl {
public int addOperation(Operation operation) throws OperationManagementDAOException {
int operationId;
PreparedStatement stmt = null;
ByteArrayOutputStream bao = null;
ObjectOutputStream oos = null;
try {
operationId = super.addOperation(operation);
operation.setCreatedTimeStamp(new Timestamp(new java.util.Date().getTime()).toString());
@ -48,12 +50,33 @@ public class PolicyOperationDAOImpl extends OperationDAOImpl {
Connection conn = OperationManagementDAOFactory.getConnection();
stmt = conn.prepareStatement("INSERT INTO DM_POLICY_OPERATION(OPERATION_ID, OPERATION_DETAILS) " +
"VALUES(?, ?)");
bao = new ByteArrayOutputStream();
oos = new ObjectOutputStream(bao);
oos.writeObject(operation);
stmt.setInt(1, operationId);
stmt.setObject(2, policyOperation);
stmt.setBytes(2, bao.toByteArray());
stmt.executeUpdate();
} catch (SQLException e) {
throw new OperationManagementDAOException("Error occurred while adding policy operation", e);
} catch (IOException e) {
throw new OperationManagementDAOException("Error occurred while serializing policy 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);
}
return operationId;

@ -46,7 +46,7 @@ public interface MonitoringDAO {
void setDeviceAsCompliance(int deviceId, int enrolmentId, int policyId) throws MonitoringDAOException;
void addNoneComplianceFeatures(int policyComplianceStatusId, int deviceId, List<ComplianceFeature>
void addNonComplianceFeatures(int policyComplianceStatusId, int deviceId, List<ComplianceFeature>
complianceFeatures)
throws MonitoringDAOException;

@ -67,7 +67,7 @@ public class FeatureDAOImpl implements FeatureDAO {
conn = this.getConnection();
String query = "INSERT INTO DM_PROFILE_FEATURES (PROFILE_ID, FEATURE_CODE, DEVICE_TYPE_ID, CONTENT, " +
"TENANT_ID) VALUES (?, ?, ?, ?, ?)";
stmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS);
stmt = conn.prepareStatement(query, new String[] {"id"});
for (ProfileFeature feature : features) {
stmt.setInt(1, profileId);
@ -113,13 +113,9 @@ public class FeatureDAOImpl implements FeatureDAO {
String query = "UPDATE DM_PROFILE_FEATURES SET CONTENT = ? WHERE PROFILE_ID = ? AND FEATURE_CODE = ? AND" +
" TENANT_ID = ?";
stmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS);
stmt = conn.prepareStatement(query);
for (ProfileFeature feature : features) {
if (conn.getMetaData().getDriverName().contains("H2")) {
stmt.setBytes(1, PolicyManagerUtil.getBytes(feature.getContent()));
} else {
stmt.setBytes(1, PolicyManagerUtil.getBytes(feature.getContent()));
}
stmt.setBytes(1, PolicyManagerUtil.getBytes(feature.getContent()));
stmt.setInt(2, profileId);
stmt.setString(3, feature.getFeatureCode());
stmt.setInt(4, tenantId);

@ -206,7 +206,7 @@ public class MonitoringDAOImpl implements MonitoringDAO {
}
@Override
public void addNoneComplianceFeatures(int policyComplianceStatusId, int deviceId, List<ComplianceFeature>
public void addNonComplianceFeatures(int policyComplianceStatusId, int deviceId, List<ComplianceFeature>
complianceFeatures) throws MonitoringDAOException {
Connection conn;
PreparedStatement stmt = null;
@ -215,7 +215,7 @@ public class MonitoringDAOImpl implements MonitoringDAO {
conn = this.getConnection();
String query = "INSERT INTO DM_POLICY_COMPLIANCE_FEATURES (COMPLIANCE_STATUS_ID, FEATURE_CODE, STATUS, " +
"TENANT_ID) VALUES (?, ?, ?, ?) ";
stmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS);
stmt = conn.prepareStatement(query);
for (ComplianceFeature feature : complianceFeatures) {
stmt.setInt(1, policyComplianceStatusId);
stmt.setString(2, feature.getFeatureCode());

@ -442,7 +442,7 @@ public class PolicyDAOImpl implements PolicyDAO {
try {
conn = this.getConnection();
String query = "INSERT INTO DM_CRITERIA (TENANT_ID, NAME) VALUES (?, ?)";
stmt = conn.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
stmt = conn.prepareStatement(query, new String[] {"id"});
stmt.setInt(1, tenantId);
stmt.setString(2, criteria.getName());
stmt.executeUpdate();
@ -622,7 +622,7 @@ public class PolicyDAOImpl implements PolicyDAO {
try {
conn = this.getConnection();
String query = "INSERT INTO DM_POLICY_CRITERIA (CRITERIA_ID, POLICY_ID) VALUES (?, ?)";
stmt = conn.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
stmt = conn.prepareStatement(query, new String[] {"id"});
List<PolicyCriterion> criteria = policy.getPolicyCriterias();
for (PolicyCriterion criterion : criteria) {
@ -1348,7 +1348,7 @@ public class PolicyDAOImpl implements PolicyDAO {
conn = this.getConnection();
String query = "INSERT INTO DM_POLICY (NAME, PROFILE_ID, TENANT_ID, PRIORITY, COMPLIANCE, OWNERSHIP_TYPE," +
"UPDATED, ACTIVE, DESCRIPTION) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
stmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS);
stmt = conn.prepareStatement(query, new String[] {"id"});
stmt.setString(1, policy.getPolicyName());
stmt.setInt(2, policy.getProfile().getProfileId());

@ -51,7 +51,7 @@ public class ProfileDAOImpl implements ProfileDAO {
conn = this.getConnection();
String query = "INSERT INTO DM_PROFILE " +
"(PROFILE_NAME,TENANT_ID, DEVICE_TYPE_ID, CREATED_TIME, UPDATED_TIME) VALUES (?, ?, ?, ?, ?)";
stmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS);
stmt = conn.prepareStatement(query, new String[] {"id"});
stmt.setString(1, profile.getProfileName());
stmt.setInt(2, tenantId);

@ -120,7 +120,7 @@ public class MonitoringManagerImpl implements MonitoringManager {
if (log.isDebugEnabled()) {
log.debug("Compliance status primary key " + complianceData.getId());
}
monitoringDAO.addNoneComplianceFeatures(complianceData.getId(), device.getId(),
monitoringDAO.addNonComplianceFeatures(complianceData.getId(), device.getId(),
complianceFeatures);
PolicyManagementDAOFactory.commitTransaction();

Loading…
Cancel
Save