mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Fix issues in data archival feature
There were few issues regarding the data retreiving SQL query and archived config operations
This commit is contained in:
parent
6b99197b54
commit
415aac1ce0
@ -111,6 +111,12 @@ public class ArchivalServiceImpl implements ArchivalService {
|
|||||||
}
|
}
|
||||||
archivalDAO.moveProfileOperations();
|
archivalDAO.moveProfileOperations();
|
||||||
|
|
||||||
|
//Purge the config operation table, DM_CONFIG_OPERATION
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("## Purging config operations");
|
||||||
|
}
|
||||||
|
archivalDAO.moveConfigOperations();
|
||||||
|
|
||||||
//Purge the enrolment mappings table, DM_ENROLMENT_OP_MAPPING
|
//Purge the enrolment mappings table, DM_ENROLMENT_OP_MAPPING
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("## Purging enrolment mappings");
|
log.debug("## Purging enrolment mappings");
|
||||||
|
|||||||
@ -41,6 +41,8 @@ public interface ArchivalDAO {
|
|||||||
|
|
||||||
void moveProfileOperations() throws ArchivalDAOException;
|
void moveProfileOperations() throws ArchivalDAOException;
|
||||||
|
|
||||||
|
void moveConfigOperations() throws ArchivalDAOException;
|
||||||
|
|
||||||
void moveEnrolmentMappings() throws ArchivalDAOException;
|
void moveEnrolmentMappings() throws ArchivalDAOException;
|
||||||
|
|
||||||
void moveOperations() throws ArchivalDAOException;
|
void moveOperations() throws ArchivalDAOException;
|
||||||
|
|||||||
@ -56,8 +56,8 @@ public class ArchivalDAOImpl implements ArchivalDAO {
|
|||||||
try {
|
try {
|
||||||
Connection conn = ArchivalSourceDAOFactory.getConnection();
|
Connection conn = ArchivalSourceDAOFactory.getConnection();
|
||||||
String sql = "SELECT DISTINCT OPERATION_ID FROM DM_ENROLMENT_OP_MAPPING " +
|
String sql = "SELECT DISTINCT OPERATION_ID FROM DM_ENROLMENT_OP_MAPPING " +
|
||||||
"WHERE CREATED_TIMESTAMP BETWEEN DATE_SUB(NOW(), INTERVAL " +
|
"WHERE CREATED_TIMESTAMP BETWEEN DATE(TIMESTAMPADD(DAY, " +
|
||||||
this.retentionPeriod + " DAY) AND NOW()";
|
this.retentionPeriod + ", NOW())) AND NOW()";
|
||||||
stmt = this.createMemoryEfficientStatement(conn);
|
stmt = this.createMemoryEfficientStatement(conn);
|
||||||
rs = stmt.executeQuery(sql);
|
rs = stmt.executeQuery(sql);
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
@ -83,7 +83,8 @@ public class ArchivalDAOImpl implements ArchivalDAO {
|
|||||||
Connection conn = ArchivalSourceDAOFactory.getConnection();
|
Connection conn = ArchivalSourceDAOFactory.getConnection();
|
||||||
String sql = "SELECT DISTINCT OPERATION_ID " +
|
String sql = "SELECT DISTINCT OPERATION_ID " +
|
||||||
" FROM DM_ENROLMENT_OP_MAPPING WHERE STATUS IN('PENDING', 'IN_PROGRESS') " +
|
" FROM DM_ENROLMENT_OP_MAPPING WHERE STATUS IN('PENDING', 'IN_PROGRESS') " +
|
||||||
" AND CREATED_TIMESTAMP BETWEEN DATE_SUB(NOW(), INTERVAL " + this.retentionPeriod +" DAY) AND NOW()";
|
" AND CREATED_TIMESTAMP BETWEEN DATE(TIMESTAMPADD(DAY, " + this.retentionPeriod +", NOW())) " +
|
||||||
|
"AND NOW()";
|
||||||
stmt = this.createMemoryEfficientStatement(conn);
|
stmt = this.createMemoryEfficientStatement(conn);
|
||||||
rs = stmt.executeQuery(sql);
|
rs = stmt.executeQuery(sql);
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
@ -337,6 +338,56 @@ public class ArchivalDAOImpl implements ArchivalDAO {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void moveConfigOperations() throws ArchivalDAOException {
|
||||||
|
Statement stmt = null;
|
||||||
|
PreparedStatement stmt2 = null;
|
||||||
|
Statement stmt3 = null;
|
||||||
|
ResultSet rs = null;
|
||||||
|
try {
|
||||||
|
Connection conn = ArchivalSourceDAOFactory.getConnection();
|
||||||
|
String sql = "SELECT * FROM DM_CONFIG_OPERATION WHERE OPERATION_ID IN " +
|
||||||
|
"(SELECT ID FROM DM_ARCHIVED_OPERATIONS)";
|
||||||
|
stmt = this.createMemoryEfficientStatement(conn);
|
||||||
|
rs = stmt.executeQuery(sql);
|
||||||
|
|
||||||
|
Connection conn2 = ArchivalDestinationDAOFactory.getConnection();
|
||||||
|
|
||||||
|
sql = "INSERT INTO DM_CONFIG_OPERATION_ARCH VALUES(?, ?, ?, ?)";
|
||||||
|
stmt2 = conn2.prepareStatement(sql);
|
||||||
|
|
||||||
|
int count = 0;
|
||||||
|
while (rs.next()) {
|
||||||
|
stmt2.setInt(1, rs.getInt("OPERATION_ID"));
|
||||||
|
stmt2.setBytes(2, rs.getBytes("OPERATION_CONFIG"));
|
||||||
|
stmt2.setInt(3, rs.getInt("ENABLED"));
|
||||||
|
stmt2.setTimestamp(4,this.currentTimestamp );
|
||||||
|
stmt2.addBatch();
|
||||||
|
|
||||||
|
if (++count % batchSize == 0) {
|
||||||
|
stmt2.executeBatch();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stmt2.executeBatch();
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug(count + " [CONFIG_OPERATION] Records copied to the archival table. Starting deletion");
|
||||||
|
}
|
||||||
|
sql = "DELETE FROM DM_CONFIG_OPERATION" +
|
||||||
|
" WHERE OPERATION_ID IN (SELECT ID FROM DM_ARCHIVED_OPERATIONS)";
|
||||||
|
stmt3 = conn.createStatement();
|
||||||
|
int affected = stmt3.executeUpdate(sql);
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug(affected + " Rows deleted");
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new ArchivalDAOException("Error occurred while moving config operations", e);
|
||||||
|
} finally {
|
||||||
|
ArchivalDAOUtil.cleanupResources(stmt, rs);
|
||||||
|
ArchivalDAOUtil.cleanupResources(stmt2);
|
||||||
|
ArchivalDAOUtil.cleanupResources(stmt3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void moveEnrolmentMappings() throws ArchivalDAOException {
|
public void moveEnrolmentMappings() throws ArchivalDAOException {
|
||||||
Statement stmt = null;
|
Statement stmt = null;
|
||||||
|
|||||||
@ -29,6 +29,7 @@ public class ArchivalTaskConfiguration {
|
|||||||
private int retentionPeriod;
|
private int retentionPeriod;
|
||||||
private int batchSize;
|
private int batchSize;
|
||||||
private PurgingTaskConfiguration purgingTaskConfiguration;
|
private PurgingTaskConfiguration purgingTaskConfiguration;
|
||||||
|
private final int MULTIPLIER = -1;
|
||||||
|
|
||||||
@XmlElement(name = "Enabled", required = true)
|
@XmlElement(name = "Enabled", required = true)
|
||||||
public boolean isEnabled() {
|
public boolean isEnabled() {
|
||||||
@ -59,7 +60,8 @@ public class ArchivalTaskConfiguration {
|
|||||||
|
|
||||||
@XmlElement(name = "RetentionPeriod", required = true)
|
@XmlElement(name = "RetentionPeriod", required = true)
|
||||||
public int getRetentionPeriod() {
|
public int getRetentionPeriod() {
|
||||||
return retentionPeriod;
|
// multiply by -1 to get the diff
|
||||||
|
return retentionPeriod * MULTIPLIER;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRetentionPeriod(int retentionPeriod) {
|
public void setRetentionPeriod(int retentionPeriod) {
|
||||||
|
|||||||
@ -52,6 +52,14 @@ CREATE TABLE IF NOT EXISTS DM_COMMAND_OPERATION_ARCH (
|
|||||||
PRIMARY KEY (OPERATION_ID)
|
PRIMARY KEY (OPERATION_ID)
|
||||||
)ENGINE = InnoDB;
|
)ENGINE = InnoDB;
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS DM_CONFIG_OPERATION_ARCH (
|
||||||
|
OPERATION_ID INTEGER NOT NULL,
|
||||||
|
OPERATION_CONFIG BLOB DEFAULT NULL,
|
||||||
|
ENABLED BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
|
ARCHIVED_AT TIMESTAMP DEFAULT NOW(),
|
||||||
|
PRIMARY KEY (OPERATION_ID)
|
||||||
|
)ENGINE = InnoDB;
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS DM_PROFILE_OPERATION_ARCH (
|
CREATE TABLE IF NOT EXISTS DM_PROFILE_OPERATION_ARCH (
|
||||||
OPERATION_ID INTEGER NOT NULL,
|
OPERATION_ID INTEGER NOT NULL,
|
||||||
ENABLED INTEGER NOT NULL DEFAULT 0,
|
ENABLED INTEGER NOT NULL DEFAULT 0,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user