From 62c6882fa26c40cef219c61c788ed54debcd5fa9 Mon Sep 17 00:00:00 2001 From: Ace Date: Wed, 13 Dec 2017 00:23:08 +0530 Subject: [PATCH] Fixing server startup issue when configured with PostgreSQL DB --- .../impl/group/PostgreSQLGroupDAOImpl.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/group/PostgreSQLGroupDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/group/PostgreSQLGroupDAOImpl.java index c7b0c6b78b..83020796ef 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/group/PostgreSQLGroupDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/group/PostgreSQLGroupDAOImpl.java @@ -39,6 +39,34 @@ import java.util.List; */ public class PostgreSQLGroupDAOImpl extends AbstractGroupDAOImpl { + @Override + public int addGroup(DeviceGroup deviceGroup, int tenantId) throws GroupManagementDAOException { + PreparedStatement stmt = null; + ResultSet rs; + int groupId = -1; + try { + Connection conn = GroupManagementDAOFactory.getConnection(); + String sql = "INSERT INTO DM_GROUP(DESCRIPTION, GROUP_NAME, OWNER, TENANT_ID) " + + "VALUES (?, ?, ?, ?) RETURNING ID"; + stmt = conn.prepareStatement(sql); + stmt.setString(1, deviceGroup.getDescription()); + stmt.setString(2, deviceGroup.getName()); + stmt.setString(3, deviceGroup.getOwner()); + stmt.setInt(4, tenantId); + stmt.execute(); + rs = stmt.getGeneratedKeys(); + if (rs.next()) { + groupId = rs.getInt(1); + } + return groupId; + } catch (SQLException e) { + throw new GroupManagementDAOException("Error occurred while adding deviceGroup '" + + deviceGroup.getName() + "'", e); + } finally { + GroupManagementDAOUtil.cleanupResources(stmt, null); + } + } + @Override public List getGroups(GroupPaginationRequest request, int tenantId) throws GroupManagementDAOException {