|
|
@ -19,6 +19,7 @@
|
|
|
|
package org.wso2.carbon.device.mgt.core.dao.impl;
|
|
|
|
package org.wso2.carbon.device.mgt.core.dao.impl;
|
|
|
|
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.Device;
|
|
|
|
import org.wso2.carbon.device.mgt.common.Device;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
|
|
|
|
import org.wso2.carbon.device.mgt.common.GroupPaginationRequest;
|
|
|
|
import org.wso2.carbon.device.mgt.common.GroupPaginationRequest;
|
|
|
|
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
|
|
|
|
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
|
|
|
|
import org.wso2.carbon.device.mgt.core.dao.GroupDAO;
|
|
|
|
import org.wso2.carbon.device.mgt.core.dao.GroupDAO;
|
|
|
@ -60,7 +61,7 @@ public class GroupDAOImpl implements GroupDAO {
|
|
|
|
return groupId;
|
|
|
|
return groupId;
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new GroupManagementDAOException("Error occurred while adding deviceGroup '" +
|
|
|
|
throw new GroupManagementDAOException("Error occurred while adding deviceGroup '" +
|
|
|
|
deviceGroup.getName() + "'", e);
|
|
|
|
deviceGroup.getName() + "'", e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
GroupManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
GroupManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -83,7 +84,7 @@ public class GroupDAOImpl implements GroupDAO {
|
|
|
|
stmt.executeUpdate();
|
|
|
|
stmt.executeUpdate();
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new GroupManagementDAOException("Error occurred while updating deviceGroup '" +
|
|
|
|
throw new GroupManagementDAOException("Error occurred while updating deviceGroup '" +
|
|
|
|
deviceGroup.getName() + "'", e);
|
|
|
|
deviceGroup.getName() + "'", e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
GroupManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
GroupManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -148,7 +149,7 @@ public class GroupDAOImpl implements GroupDAO {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new GroupManagementDAOException("Error occurred while obtaining information of Device Group '" +
|
|
|
|
throw new GroupManagementDAOException("Error occurred while obtaining information of Device Group '" +
|
|
|
|
groupId + "'", e);
|
|
|
|
groupId + "'", e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
GroupManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
GroupManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -204,7 +205,12 @@ public class GroupDAOImpl implements GroupDAO {
|
|
|
|
hasOwner = true;
|
|
|
|
hasOwner = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (hasLimit) {
|
|
|
|
if (hasLimit) {
|
|
|
|
sql += " LIMIT ?, ?";
|
|
|
|
if (conn.getMetaData().getDatabaseProductName().contains(DeviceManagementConstants.DataBaseTypes.DB_TYPE_ORACLE) ||
|
|
|
|
|
|
|
|
conn.getMetaData().getDatabaseProductName().contains(DeviceManagementConstants.DataBaseTypes.DB_TYPE_MSSQL)) {
|
|
|
|
|
|
|
|
sql += " OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
sql += " LIMIT ?, ?";
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int paramIndex = 1;
|
|
|
|
int paramIndex = 1;
|
|
|
@ -267,7 +273,12 @@ public class GroupDAOImpl implements GroupDAO {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sql += ")";
|
|
|
|
sql += ")";
|
|
|
|
if (hasLimit) {
|
|
|
|
if (hasLimit) {
|
|
|
|
sql += " LIMIT ?, ?";
|
|
|
|
if (conn.getMetaData().getDatabaseProductName().contains(DeviceManagementConstants.DataBaseTypes.DB_TYPE_ORACLE) ||
|
|
|
|
|
|
|
|
conn.getMetaData().getDatabaseProductName().contains(DeviceManagementConstants.DataBaseTypes.DB_TYPE_MSSQL)) {
|
|
|
|
|
|
|
|
sql += " OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
sql += " LIMIT ?, ?";
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int paramIndex = 1;
|
|
|
|
int paramIndex = 1;
|
|
|
@ -513,7 +524,13 @@ public class GroupDAOImpl implements GroupDAO {
|
|
|
|
" DM_DEVICE d, (" +
|
|
|
|
" DM_DEVICE d, (" +
|
|
|
|
"SELECT dgm.DEVICE_ID FROM DM_DEVICE_GROUP_MAP dgm WHERE dgm.GROUP_ID = ?) dgm1 " +
|
|
|
|
"SELECT dgm.DEVICE_ID FROM DM_DEVICE_GROUP_MAP dgm WHERE dgm.GROUP_ID = ?) dgm1 " +
|
|
|
|
"WHERE d.ID = dgm1.DEVICE_ID AND d.TENANT_ID = ?) gd, DM_DEVICE_TYPE t " +
|
|
|
|
"WHERE d.ID = dgm1.DEVICE_ID AND d.TENANT_ID = ?) gd, DM_DEVICE_TYPE t " +
|
|
|
|
"WHERE gd.DEVICE_TYPE_ID = t.ID) d1 WHERE d1.DEVICE_ID = e.DEVICE_ID AND TENANT_ID = ? LIMIT ? , ?";
|
|
|
|
"WHERE gd.DEVICE_TYPE_ID = t.ID) d1 WHERE d1.DEVICE_ID = e.DEVICE_ID AND TENANT_ID = ?";
|
|
|
|
|
|
|
|
if (conn.getMetaData().getDatabaseProductName().contains(DeviceManagementConstants.DataBaseTypes.DB_TYPE_ORACLE) ||
|
|
|
|
|
|
|
|
conn.getMetaData().getDatabaseProductName().contains(DeviceManagementConstants.DataBaseTypes.DB_TYPE_MSSQL)) {
|
|
|
|
|
|
|
|
sql += " OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
sql += " LIMIT ?, ?";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt.setInt(1, groupId);
|
|
|
|
stmt.setInt(1, groupId);
|
|
|
@ -531,7 +548,7 @@ public class GroupDAOImpl implements GroupDAO {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new GroupManagementDAOException("Error occurred while retrieving information of all " +
|
|
|
|
throw new GroupManagementDAOException("Error occurred while retrieving information of all " +
|
|
|
|
"registered devices", e);
|
|
|
|
"registered devices", e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -728,7 +745,7 @@ public class GroupDAOImpl implements GroupDAO {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new GroupManagementDAOException("Error occurred while getting own groups of user '"
|
|
|
|
throw new GroupManagementDAOException("Error occurred while getting own groups of user '"
|
|
|
|
+ username + "'", e);
|
|
|
|
+ username + "'", e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
GroupManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
GroupManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -753,7 +770,7 @@ public class GroupDAOImpl implements GroupDAO {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new GroupManagementDAOException("Error occurred while getting own groups of user '"
|
|
|
|
throw new GroupManagementDAOException("Error occurred while getting own groups of user '"
|
|
|
|
+ username + "'", e);
|
|
|
|
+ username + "'", e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
GroupManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
GroupManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -778,7 +795,7 @@ public class GroupDAOImpl implements GroupDAO {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new GroupManagementDAOException("Error occurred while getting own groups count of user '"
|
|
|
|
throw new GroupManagementDAOException("Error occurred while getting own groups count of user '"
|
|
|
|
+ username + "'", e);
|
|
|
|
+ username + "'", e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
GroupManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
GroupManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|