From ecc87f370ccf0344929b56660b5363ca048c04d9 Mon Sep 17 00:00:00 2001 From: Megala Date: Thu, 29 Sep 2016 13:19:33 +0530 Subject: [PATCH] Fixing oracle error --- .../mgt/dao/impl/GenericOperationDAOImpl.java | 43 ++++++++----------- 1 file changed, 18 insertions(+), 25 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java index 089ae9f276..a7e2d06728 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java @@ -407,36 +407,29 @@ public class GenericOperationDAOImpl implements OperationDAO { // sql = sql + " OFFSET ?"; // } - - String sql = "SELECT opm.ENROLMENT_ID, opm.CREATED_TIMESTAMP, opm.UPDATED_TIMESTAMP, opm.OPERATION_ID,\n" + - "op.OPERATION_CODE, op.TYPE as OPERATION_TYPE, opm.STATUS, en.DEVICE_ID,\n" + - "ops.RECEIVED_TIMESTAMP, ops.ID as OP_RES_ID, ops.OPERATION_RESPONSE,\n" + - "de.DEVICE_IDENTIFICATION, dt.NAME as DEVICE_TYPE\n" + - "FROM DM_ENROLMENT_OP_MAPPING AS opm\n" + - "LEFT JOIN DM_OPERATION AS op ON opm.OPERATION_ID = op.ID \n" + - "LEFT JOIN DM_ENROLMENT as en ON opm.ENROLMENT_ID = en.ID \n" + - "LEFT JOIN DM_DEVICE as de ON en.DEVICE_ID = de.ID \n" + - "LEFT JOIN DM_DEVICE_TYPE as dt ON dt.ID = de.DEVICE_TYPE_ID \n" + - "LEFT JOIN DM_DEVICE_OPERATION_RESPONSE as ops ON \n" + - "opm.ENROLMENT_ID = ops.ENROLMENT_ID AND opm.OPERATION_ID = ops.OPERATION_ID \n" + - "WHERE opm.UPDATED_TIMESTAMP > ? \n" + - "AND de.TENANT_ID = ? \n"; - - if(timestamp == 0){ - sql += "ORDER BY opm.OPERATION_ID LIMIT ? OFFSET ?"; - }else{ - sql += "ORDER BY opm.UPDATED_TIMESTAMP asc LIMIT ? OFFSET ?"; + String sql = "SELECT opm.ENROLMENT_ID, opm.CREATED_TIMESTAMP, opm.UPDATED_TIMESTAMP, opm.OPERATION_ID,\n" + + "op.OPERATION_CODE, op.TYPE OPERATION_TYPE, opm.STATUS, en.DEVICE_ID,\n" + + "ops.RECEIVED_TIMESTAMP, ops.ID OP_RES_ID, ops.OPERATION_RESPONSE,\n" + + "de.DEVICE_IDENTIFICATION, dt.NAME DEVICE_TYPE\n" + "FROM DM_ENROLMENT_OP_MAPPING opm\n" + + "LEFT JOIN DM_OPERATION op ON opm.OPERATION_ID = op.ID \n" + + "LEFT JOIN DM_ENROLMENT en ON opm.ENROLMENT_ID = en.ID \n" + + "LEFT JOIN DM_DEVICE de ON en.DEVICE_ID = de.ID \n" + + "LEFT JOIN DM_DEVICE_TYPE dt ON dt.ID = de.DEVICE_TYPE_ID \n" + + "LEFT JOIN DM_DEVICE_OPERATION_RESPONSE ops ON \n" + + "opm.ENROLMENT_ID = ops.ENROLMENT_ID AND opm.OPERATION_ID = ops.OPERATION_ID \n" + + "WHERE opm.UPDATED_TIMESTAMP > ? \n" + "AND de.TENANT_ID = ? \n"; + + if (timestamp == 0) { + sql += "ORDER BY opm.OPERATION_ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; + } else { + sql += "ORDER BY opm.UPDATED_TIMESTAMP asc OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; } - - - stmt = conn.prepareStatement(sql); - stmt.setLong(1, timestamp); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); stmt.setInt(2, tenantId); - stmt.setInt(3, limit); - stmt.setInt(4, offset); + stmt.setInt(3, offset); + stmt.setInt(4, limit); rs = stmt.executeQuery();