From 40ee310f42fb5d55ec2d1d9b12eff8a0a7bd1258 Mon Sep 17 00:00:00 2001 From: inosh-perera Date: Fri, 16 Jan 2015 20:14:48 +0530 Subject: [PATCH] returning auto incremented id --- .../carbon/device/mgt/mobile/dao/OperationDAO.java | 4 ++-- .../device/mgt/mobile/dao/impl/OperationDAOImpl.java | 11 +++++++---- .../client/src/org/wso2/cdm/agent/ServerDetails.java | 1 + 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/OperationDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/OperationDAO.java index 8fba815ace..dbb824b556 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/OperationDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/OperationDAO.java @@ -13,10 +13,10 @@ public interface OperationDAO { /** * Add a new operation to plugin operation table. * @param operation Operation object that holds data related to the operation to be inserted. - * @return The status of the operation. If the insert was successful or not. + * @return The last inserted Id is returned, if the insertion was unsuccessful -1 is returned. * @throws MobileDeviceManagementDAOException */ - boolean addOperation(Operation operation) throws MobileDeviceManagementDAOException; + int addOperation(Operation operation) throws MobileDeviceManagementDAOException; /** * Update a operation in the operation table. diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/OperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/OperationDAOImpl.java index 3e57869052..ffac537cd6 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/OperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/dao/impl/OperationDAOImpl.java @@ -26,9 +26,9 @@ public class OperationDAOImpl implements OperationDAO { } @Override - public boolean addOperation(Operation operation) + public int addOperation(Operation operation) throws MobileDeviceManagementDAOException { - boolean status = false; + int status = -1; Connection conn = null; PreparedStatement stmt = null; try { @@ -36,12 +36,15 @@ public class OperationDAOImpl implements OperationDAO { String createDBQuery = "INSERT INTO MBL_OPERATION(FEATURE_CODE, CREATED_DATE) VALUES ( ?, ?)"; - stmt = conn.prepareStatement(createDBQuery); + stmt = conn.prepareStatement(createDBQuery, new String[] { "OPERATION_ID" }); stmt.setString(1, operation.getFeatureCode()); stmt.setInt(2, operation.getCreatedDate()); int rows = stmt.executeUpdate(); if (rows > 0) { - status = true; + ResultSet rs = stmt.getGeneratedKeys(); + if (rs != null && rs.next()) { + status = rs.getInt(1); + } } } catch (SQLException e) { String msg = "Error occurred while adding feature code - '" + diff --git a/product/modules/agents/android/client/src/org/wso2/cdm/agent/ServerDetails.java b/product/modules/agents/android/client/src/org/wso2/cdm/agent/ServerDetails.java index 5643b791e9..5c65322b5b 100644 --- a/product/modules/agents/android/client/src/org/wso2/cdm/agent/ServerDetails.java +++ b/product/modules/agents/android/client/src/org/wso2/cdm/agent/ServerDetails.java @@ -86,6 +86,7 @@ public class ServerDetails extends Activity { getResources().getString(R.string.shared_pref_ip)); regId = Preference.get(context.getApplicationContext().getApplicationContext(), getResources().getString(R.string.shared_pref_regId)); + //heck if we have the IP saved previously. if (ipSaved != null) { serverIP.setText(ipSaved); CommonUtilities.setServerURL(ipSaved);