Added MSSQL, PostgreSQL and Oracle db support for Notification feature.

revert-70aa11f8
harshanl 8 years ago
parent 35ea88b9de
commit 657e4864fb

@ -30,379 +30,385 @@
<PermissionConfiguration> <PermissionConfiguration>
<APIVersion></APIVersion> <APIVersion></APIVersion>
<!--Permission Tree Name--> <!--Permission Tree Name-->
<Permission> <Permission>
<name>Device Management</name> <name>Device Management</name>
<path>/device-mgt</path> <path>/device-mgt</path>
<url>/</url> <url>/</url>
<method>GET</method> <method>GET</method>
</Permission> </Permission>
<!-- Admin Permissions --> <!-- Admin Permissions -->
<Permission> <Permission>
<name>Device Management Admin</name> <name>Device Management Admin</name>
<path>/device-mgt/admin</path> <path>/device-mgt/admin</path>
<url>/</url> <url>/</url>
<method>GET</method> <method>GET</method>
</Permission> </Permission>
<Permission> <Permission>
<name>Devices</name> <name>Devices</name>
<path>/device-mgt/admin/devices</path> <path>/device-mgt/admin/devices</path>
<url>/</url> <url>/</url>
<method>GET</method> <method>GET</method>
</Permission> </Permission>
<!-- Device related APIs --> <!-- Device related APIs -->
<Permission> <Permission>
<name>List devices</name> <name>List devices</name>
<path>/device-mgt/admin/devices/List</path> <path>/device-mgt/admin/devices/List</path>
<url>/devices</url> <url>/devices</url>
<method>GET</method> <method>GET</method>
</Permission> </Permission>
<Permission> <Permission>
<name>Search devices</name> <name>Search devices</name>
<path>/device-mgt/admin/devices/Search</path> <path>/device-mgt/admin/devices/Search</path>
<url>/devices/search-devices</url> <url>/devices/search-devices</url>
<method>POST</method> <method>POST</method>
</Permission> </Permission>
<Permission> <Permission>
<name>View device</name> <name>View device</name>
<path>/device-mgt/admin/devices/View</path> <path>/device-mgt/admin/devices/View</path>
<url>/devices/*/*</url> <url>/devices/*/*</url>
<method>GET</method> <method>GET</method>
</Permission> </Permission>
<Permission> <Permission>
<name>View device applications</name> <name>View device info</name>
<path>/device-mgt/admin/devices/View-Applications</path> <path>/device-mgt/admin/devices/View</path>
<url>/devices/*/*/applications</url> <url>/devices/*/*/info</url>
<method>GET</method> <method>GET</method>
</Permission> </Permission>
<Permission> <Permission>
<name>View device effective-policy</name> <name>View device applications</name>
<path>/device-mgt/admin/devices/View-Active-Policy</path> <path>/device-mgt/admin/devices/View-Applications</path>
<url>/devices/*/*/effective-policy</url> <url>/devices/*/*/applications</url>
<method>GET</method> <method>GET</method>
</Permission> </Permission>
<Permission> <Permission>
<name>View devices feature</name> <name>View device effective-policy</name>
<path>/device-mgt/admin/devices/View-Features</path> <path>/device-mgt/admin/devices/View-Active-Policy</path>
<url>/devices/*/*/features</url> <url>/devices/*/*/effective-policy</url>
<method>GET</method> <method>GET</method>
</Permission> </Permission>
<Permission> <Permission>
<name>View device operations</name> <name>View devices feature</name>
<path>/device-mgt/admin/devices/View-Operations</path> <path>/device-mgt/admin/devices/View-Features</path>
<url>/devices/*/*/operations</url> <url>/devices/*/*/features</url>
<method>GET</method> <method>GET</method>
</Permission> </Permission>
<Permission> <Permission>
<name>View Compliance Data</name> <name>View device operations</name>
<path>/device-mgt/admin/devices/View-Compliance-Data</path> <path>/device-mgt/admin/devices/View-Operations</path>
<url>/devices/*/*/compliance-data</url> <url>/devices/*/*/operations</url>
<method>GET</method> <method>GET</method>
</Permission> </Permission>
<Permission> <Permission>
<name>List all devices</name> <name>View Compliance Data</name>
<path>/device-mgt/admin/devices/Admin-View</path> <path>/device-mgt/admin/devices/View-Compliance-Data</path>
<url>/admin/devices</url> <url>/devices/*/*/compliance-data</url>
<method>GET</method> <method>GET</method>
</Permission> </Permission>
<Permission> <Permission>
<name>View device types</name> <name>List all devices</name>
<path>/device-mgt/admin/devices/Admin-DeviceType-View</path> <path>/device-mgt/admin/devices/Admin-View</path>
<url>/admin/device-types</url> <url>/admin/devices</url>
<method>GET</method> <method>GET</method>
</Permission> </Permission>
<!-- End of Device related APIs --> <Permission>
<Permission> <name>View device types</name>
<name>Policies</name> <path>/device-mgt/admin/devices/Admin-DeviceType-View</path>
<path>/device-mgt/admin/policies</path> <url>/admin/device-types</url>
<url>/</url> <method>GET</method>
<method>GET</method> </Permission>
</Permission> <!-- End of Device related APIs -->
<!-- Policy related APIs --> <Permission>
<Permission> <name>Policies</name>
<name>List policies</name> <path>/device-mgt/admin/policies</path>
<path>/device-mgt/admin/policies/List</path> <url>/</url>
<url>/policies</url> <method>GET</method>
<method>GET</method> </Permission>
</Permission> <!-- Policy related APIs -->
<Permission> <Permission>
<name>Add Policy</name> <name>List policies</name>
<path>/device-mgt/admin/policies/Add</path> <path>/device-mgt/admin/policies/List</path>
<url>/policies</url> <url>/policies</url>
<method>POST</method> <method>GET</method>
</Permission> </Permission>
<Permission> <Permission>
<name>Activate policy</name> <name>Add Policy</name>
<path>/device-mgt/admin/policies/Activate-Policy</path> <path>/device-mgt/admin/policies/Add</path>
<url>/policies/activate-policy</url> <url>/policies</url>
<method>PUT</method> <method>POST</method>
</Permission> </Permission>
<Permission> <Permission>
<name>Deactivate Policy</name> <name>Activate policy</name>
<path>/device-mgt/admin/policies/Deactivate-Policy</path> <path>/device-mgt/admin/policies/Activate-Policy</path>
<url>/policies/deactivate-policy</url> <url>/policies/activate-policy</url>
<method>PUT</method> <method>PUT</method>
</Permission> </Permission>
<Permission> <Permission>
<name>Remove Policy</name> <name>Deactivate Policy</name>
<path>/device-mgt/admin/policies/Remove</path> <path>/device-mgt/admin/policies/Deactivate-Policy</path>
<url>/policies/remove-policy</url> <url>/policies/deactivate-policy</url>
<method>POST</method> <method>PUT</method>
</Permission> </Permission>
<Permission> <Permission>
<name>View Policy</name> <name>Remove Policy</name>
<path>/device-mgt/admin/policies/View</path> <path>/device-mgt/admin/policies/Remove</path>
<url>/policies/*</url> <url>/policies/remove-policy</url>
<method>GET</method> <method>POST</method>
</Permission> </Permission>
<Permission> <Permission>
<name>Update Policy</name> <name>View Policy</name>
<path>/device-mgt/admin/policies/Update</path> <path>/device-mgt/admin/policies/View</path>
<url>/policies/*</url> <url>/policies/*</url>
<method>PUT</method> <method>GET</method>
</Permission> </Permission>
<Permission> <Permission>
<name>Update Policy</name> <name>Update Policy</name>
<path>/device-mgt/admin/policies/Update</path> <path>/device-mgt/admin/policies/Update</path>
<url>/policies/apply-changes</url> <url>/policies/*</url>
<method>PUT</method> <method>PUT</method>
</Permission> </Permission>
<Permission> <Permission>
<name>Update Policy</name> <name>Update Policy</name>
<path>/device-mgt/admin/policies/Change-Priority</path> <path>/device-mgt/admin/policies/Update</path>
<url>/policies/priorities</url> <url>/policies/apply-changes</url>
<method>PUT</method> <method>PUT</method>
</Permission> </Permission>
<!-- End of Policy related APIs --> <Permission>
<Permission> <name>Update Policy</name>
<name>Notifications</name> <path>/device-mgt/admin/policies/Change-Priority</path>
<path>/device-mgt/admin/notifications</path> <url>/policies/priorities</url>
<url>/</url> <method>PUT</method>
<method>GET</method> </Permission>
</Permission> <!-- End of Policy related APIs -->
<!-- Notification related APIs --> <Permission>
<Permission> <name>Notifications</name>
<name>View notifications</name> <path>/device-mgt/admin/notifications</path>
<path>/device-mgt/admin/notifications/View</path> <url>/</url>
<url>/notifications</url> <method>GET</method>
<method>GET</method> </Permission>
</Permission> <!-- Notification related APIs -->
<Permission> <Permission>
<name>Mark checked notifications</name> <name>View notifications</name>
<path>/device-mgt/admin/notifications/View</path> <path>/device-mgt/admin/notifications/View</path>
<url>/notifications/*/mark-checked</url> <url>/notifications</url>
<method>PUT</method> <method>GET</method>
</Permission> </Permission>
<!-- End of Notification related APIs --> <Permission>
<Permission> <name>Mark checked notifications</name>
<name>Users</name> <path>/device-mgt/admin/notifications/View</path>
<path>/device-mgt/admin/users</path> <url>/notifications/*/mark-checked</url>
<url>/</url> <method>PUT</method>
<method>GET</method> </Permission>
</Permission> <!-- End of Notification related APIs -->
<!-- User related APIs --> <Permission>
<Permission> <name>Users</name>
<name>List users</name> <path>/device-mgt/admin/users</path>
<path>/device-mgt/admin/users/List</path> <url>/</url>
<url>/users</url> <method>GET</method>
<method>GET</method> </Permission>
</Permission> <!-- User related APIs -->
<Permission> <Permission>
<name>Add user</name> <name>List users</name>
<path>/device-mgt/admin/users/Add</path> <path>/device-mgt/admin/users/List</path>
<url>/users</url> <url>/users</url>
<method>POST</method> <method>GET</method>
</Permission> </Permission>
<Permission> <Permission>
<name>List users</name> <name>Add user</name>
<path>/device-mgt/admin/users/Search</path> <path>/device-mgt/admin/users/Add</path>
<url>/users/search/usernames</url> <url>/users</url>
<method>GET</method> <method>POST</method>
</Permission> </Permission>
<Permission> <Permission>
<name>Remove user</name> <name>List users</name>
<path>/device-mgt/admin/users/Remove</path> <path>/device-mgt/admin/users/Search</path>
<url>/users/*</url> <url>/users/search/usernames</url>
<method>DELETE</method> <method>GET</method>
</Permission> </Permission>
<Permission> <Permission>
<name>View user</name> <name>Remove user</name>
<path>/device-mgt/admin/users/View</path> <path>/device-mgt/admin/users/Remove</path>
<url>/users/*</url> <url>/users/*</url>
<method>GET</method> <method>DELETE</method>
</Permission> </Permission>
<Permission> <Permission>
<name>Update user</name> <name>View user</name>
<path>/device-mgt/admin/users/Update</path> <path>/device-mgt/admin/users/View</path>
<url>/users/*</url> <url>/users/*</url>
<method>PUT</method> <method>GET</method>
</Permission> </Permission>
<Permission> <Permission>
<name>Update user credentials</name> <name>Update user</name>
<path>/device-mgt/admin/users/Change-Password</path> <path>/device-mgt/admin/users/Update</path>
<url>/users/*/credentials</url> <url>/users/*</url>
<method>PUT</method> <method>PUT</method>
</Permission> </Permission>
<Permission> <Permission>
<name>View assigned role</name> <name>Update user credentials</name>
<path>/device-mgt/admin/roles/Assigned-Roles</path> <path>/device-mgt/admin/users/Change-Password</path>
<url>/users/*/roles</url> <url>/users/*/credentials</url>
<method>GET</method> <method>PUT</method>
</Permission> </Permission>
<Permission> <Permission>
<name>Change any user credentials</name> <name>View assigned role</name>
<path>/device-mgt/admin/users/Change-Password-Any</path> <path>/device-mgt/admin/roles/Assigned-Roles</path>
<url>/admin/users/*/credentials</url> <url>/users/*/roles</url>
<method>POST</method> <method>GET</method>
</Permission> </Permission>
<Permission> <Permission>
<name>Send invitation mail</name> <name>Change any user credentials</name>
<path>/device-mgt/admin/users/Send-invitations</path> <path>/device-mgt/admin/users/Change-Password-Any</path>
<url>/users/send-invitation</url> <url>/admin/users/*/credentials</url>
<method>POST</method> <method>POST</method>
</Permission> </Permission>
<!-- End of User related APIs --> <Permission>
<Permission> <name>Send invitation mail</name>
<name>Roles</name> <path>/device-mgt/admin/users/Send-invitations</path>
<path>/device-mgt/admin/roles</path> <url>/users/send-invitation</url>
<url>/</url> <method>POST</method>
<method>GET</method> </Permission>
</Permission> <!-- End of User related APIs -->
<!-- Role related APIs --> <Permission>
<Permission> <name>Roles</name>
<name>List roles</name> <path>/device-mgt/admin/roles</path>
<path>/device-mgt/admin/roles/List</path> <url>/</url>
<url>/roles</url> <method>GET</method>
<method>GET</method> </Permission>
</Permission> <!-- Role related APIs -->
<Permission> <Permission>
<name>Add role</name> <name>List roles</name>
<path>/device-mgt/admin/roles/Add</path> <path>/device-mgt/admin/roles/List</path>
<url>/roles</url> <url>/roles</url>
<method>POST</method> <method>GET</method>
</Permission> </Permission>
<Permission> <Permission>
<name>Remove role</name> <name>Add role</name>
<path>/device-mgt/admin/roles/Remove</path> <path>/device-mgt/admin/roles/Add</path>
<url>/roles/*</url> <url>/roles</url>
<method>DELETE</method> <method>POST</method>
</Permission> </Permission>
<Permission> <Permission>
<name>View role</name> <name>Remove role</name>
<path>/device-mgt/admin/roles/View</path> <path>/device-mgt/admin/roles/Remove</path>
<url>/roles/*</url> <url>/roles/*</url>
<method>GET</method> <method>DELETE</method>
</Permission> </Permission>
<Permission> <Permission>
<name>Update role</name> <name>View role</name>
<path>/device-mgt/admin/roles/Update</path> <path>/device-mgt/admin/roles/View</path>
<url>/roles/*</url> <url>/roles/*</url>
<method>PUT</method> <method>GET</method>
</Permission> </Permission>
<Permission> <Permission>
<name>View role permissions</name> <name>Update role</name>
<path>/device-mgt/admin/roles/View-Permission</path> <path>/device-mgt/admin/roles/Update</path>
<url>/roles/*/permissions</url> <url>/roles/*</url>
<method>GET</method> <method>PUT</method>
</Permission> </Permission>
<Permission> <Permission>
<name>Add Users to role</name> <name>View role permissions</name>
<path>/device-mgt/admin/roles/Add-Users</path> <path>/device-mgt/admin/roles/View-Permission</path>
<url>/roles/*/users</url> <url>/roles/*/permissions</url>
<method>PUT</method> <method>GET</method>
</Permission> </Permission>
<!-- End of Role related APIs --> <Permission>
<Permission> <name>Add Users to role</name>
<name>Configurations</name> <path>/device-mgt/admin/roles/Add-Users</path>
<path>/device-mgt/admin/general-configs</path> <url>/roles/*/users</url>
<url>/</url> <method>PUT</method>
<method>GET</method> </Permission>
</Permission> <!-- End of Role related APIs -->
<!-- Configuration related APIs --> <Permission>
<Permission> <name>Configurations</name>
<name>View configuration</name> <path>/device-mgt/admin/general-configs</path>
<path>/device-mgt/admin/general-configuration/View</path> <url>/</url>
<url>/configuration</url> <method>GET</method>
<method>GET</method> </Permission>
</Permission> <!-- Configuration related APIs -->
<Permission> <Permission>
<name>Update configuration</name> <name>View configuration</name>
<path>/device-mgt/admin/general-configuration/Update</path> <path>/device-mgt/admin/general-configuration/View</path>
<url>/configuration</url> <url>/configuration</url>
<method>PUT</method> <method>GET</method>
</Permission> </Permission>
<!-- End of Configuration related APIs --> <Permission>
<Permission> <name>Update configuration</name>
<name>Activities</name> <path>/device-mgt/admin/general-configuration/Update</path>
<path>/device-mgt/admin/activities</path> <url>/configuration</url>
<url>/</url> <method>PUT</method>
<method>GET</method> </Permission>
</Permission> <!-- End of Configuration related APIs -->
<!-- Activity related APIs --> <Permission>
<Permission> <name>Activities</name>
<name>View Activities</name> <path>/device-mgt/admin/activities</path>
<path>/device-mgt/admin/activities/View</path> <url>/</url>
<url>/activities</url> <method>GET</method>
<method>GET</method> </Permission>
</Permission> <!-- Activity related APIs -->
<Permission> <Permission>
<name>View Activity Details</name> <name>View Activities</name>
<path>/device-mgt/admin/activities/View</path> <path>/device-mgt/admin/activities/View</path>
<url>/activities/*</url> <url>/activities</url>
<method>GET</method> <method>GET</method>
</Permission> </Permission>
<!-- End of Activity related APIs --> <Permission>
<Permission> <name>View Activity Details</name>
<name>Applications</name> <path>/device-mgt/admin/activities/View</path>
<path>/device-mgt/admin/applications</path> <url>/activities/*</url>
<url>/</url> <method>GET</method>
<method>GET</method> </Permission>
</Permission> <!-- End of Activity related APIs -->
<!-- Application related APIs --> <Permission>
<Permission> <name>Applications</name>
<name>Install Applications</name> <path>/device-mgt/admin/applications</path>
<path>/device-mgt/admin/application/Install</path> <url>/</url>
<url>/admin/applications/install-application</url> <method>GET</method>
<method>POST</method> </Permission>
</Permission> <!-- Application related APIs -->
<Permission> <Permission>
<name>Uninstall-Applications</name> <name>Install Applications</name>
<path>/device-mgt/admin/application/Uninstall</path> <path>/device-mgt/admin/application/Install</path>
<url>/admin/applications/uninstall-application</url> <url>/admin/applications/install-application</url>
<method>POST</method> <method>POST</method>
</Permission> </Permission>
<!-- End of Application related APIs --> <Permission>
<!-- End of Admin Permissions --> <name>Uninstall-Applications</name>
<!-- User Permissions --> <path>/device-mgt/admin/application/Uninstall</path>
<Permission> <url>/admin/applications/uninstall-application</url>
<name>Device Management User</name> <method>POST</method>
<path>/device-mgt/user</path> </Permission>
<url>/</url> <!-- End of Application related APIs -->
<method>GET</method> <!-- End of Admin Permissions -->
</Permission> <!-- User Permissions -->
<Permission> <Permission>
<name>User Devices</name> <name>Device Management User</name>
<path>/device-mgt/user/devices</path> <path>/device-mgt/user</path>
<url>/</url> <url>/</url>
<method>GET</method> <method>GET</method>
</Permission> </Permission>
<Permission> <Permission>
<name>User Policies</name> <name>User Devices</name>
<path>/device-mgt/user/policies</path> <path>/device-mgt/user/devices</path>
<url>/</url> <url>/</url>
<method>GET</method> <method>GET</method>
</Permission> </Permission>
<Permission> <Permission>
<name>User Notifications</name> <name>User Policies</name>
<path>/device-mgt/user/notifications</path> <path>/device-mgt/user/policies</path>
<url>/</url> <url>/</url>
<method>GET</method> <method>GET</method>
</Permission> </Permission>
<Permission> <Permission>
<name>User Operations</name> <name>User Notifications</name>
<path>/device-mgt/user/operations</path> <path>/device-mgt/user/notifications</path>
<url>/</url> <url>/</url>
<method>GET</method> <method>GET</method>
</Permission> </Permission>
<!-- End of User Permissions --> <Permission>
<name>User Operations</name>
<path>/device-mgt/user/operations</path>
<url>/</url>
<method>GET</method>
</Permission>
<!-- End of User Permissions -->
<!--End of Permission Tree--> <!--End of Permission Tree-->
</PermissionConfiguration> </PermissionConfiguration>

@ -20,11 +20,13 @@ package org.wso2.carbon.device.mgt.core.notification.mgt.dao;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.common.IllegalTransactionStateException; import org.wso2.carbon.device.mgt.common.IllegalTransactionStateException;
import org.wso2.carbon.device.mgt.common.TransactionManagementException; import org.wso2.carbon.device.mgt.common.TransactionManagementException;
import org.wso2.carbon.device.mgt.common.UnsupportedDatabaseEngineException;
import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig; import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig;
import org.wso2.carbon.device.mgt.core.config.datasource.JNDILookupDefinition; import org.wso2.carbon.device.mgt.core.config.datasource.JNDILookupDefinition;
import org.wso2.carbon.device.mgt.core.notification.mgt.dao.impl.NotificationDAOImpl; import org.wso2.carbon.device.mgt.core.notification.mgt.dao.impl.*;
import org.wso2.carbon.device.mgt.core.notification.mgt.dao.util.NotificationDAOUtil; import org.wso2.carbon.device.mgt.core.notification.mgt.dao.util.NotificationDAOUtil;
import javax.sql.DataSource; import javax.sql.DataSource;
@ -39,21 +41,48 @@ import java.util.List;
public class NotificationManagementDAOFactory { public class NotificationManagementDAOFactory {
private static DataSource dataSource; private static DataSource dataSource;
private static String databaseEngine;
private static final Log log = LogFactory.getLog(NotificationManagementDAOFactory.class); private static final Log log = LogFactory.getLog(NotificationManagementDAOFactory.class);
private static ThreadLocal<Connection> currentConnection = new ThreadLocal<Connection>(); private static ThreadLocal<Connection> currentConnection = new ThreadLocal<Connection>();
public static NotificationDAO getNotificationDAO() { public static NotificationDAO getNotificationDAO() {
return new NotificationDAOImpl(); if (databaseEngine != null) {
switch (databaseEngine) {
case DeviceManagementConstants.DataBaseTypes.DB_TYPE_ORACLE:
return new OracleNotificationDAOImpl();
case DeviceManagementConstants.DataBaseTypes.DB_TYPE_MSSQL:
return new SQLServerNotificationDAOImpl();
case DeviceManagementConstants.DataBaseTypes.DB_TYPE_POSTGRESQL:
return new PostgreSQLNotificationDAOImpl();
case DeviceManagementConstants.DataBaseTypes.DB_TYPE_H2:
case DeviceManagementConstants.DataBaseTypes.DB_TYPE_MYSQL:
return new GenericNotificationDAOImpl();
default:
throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine);
}
}
throw new IllegalStateException("Database engine has not initialized properly.");
} }
public static void init(DataSourceConfig config) { public static void init(DataSourceConfig config) {
dataSource = resolveDataSource(config); dataSource = resolveDataSource(config);
try {
databaseEngine = dataSource.getConnection().getMetaData().getDatabaseProductName();
} catch (SQLException e) {
log.error("Error occurred while retrieving config.datasource connection", e);
}
} }
public static void init(DataSource dtSource) { public static void init(DataSource dtSource) {
dataSource = dtSource; dataSource = dtSource;
try {
databaseEngine = dataSource.getConnection().getMetaData().getDatabaseProductName();
} catch (SQLException e) {
log.error("Error occurred while retrieving config.datasource connection", e);
}
} }
public static void beginTransaction() throws TransactionManagementException { public static void beginTransaction() throws TransactionManagementException {
Connection conn = currentConnection.get(); Connection conn = currentConnection.get();
if (conn != null) { if (conn != null) {

@ -35,7 +35,7 @@ import java.util.List;
/** /**
* Implementation of NotificationDAO which includes the methods to do CRUD operations on notification. * Implementation of NotificationDAO which includes the methods to do CRUD operations on notification.
*/ */
public abstract class NotificationDAOImpl implements NotificationDAO { public abstract class AbstractNotificationDAOImpl implements NotificationDAO {
@Override @Override
public int addNotification(int deviceId, int tenantId, public int addNotification(int deviceId, int tenantId,
@ -87,7 +87,7 @@ public abstract class NotificationDAOImpl implements NotificationDAO {
rs = stmt.executeQuery(); rs = stmt.executeQuery();
while (rs.next()) { while (rs.next()) {
notification = this.getNotification(rs); notification = NotificationDAOUtil.getNotification(rs);
} }
} catch (SQLException e) { } catch (SQLException e) {
throw new NotificationManagementException( throw new NotificationManagementException(
@ -165,7 +165,7 @@ public abstract class NotificationDAOImpl implements NotificationDAO {
rs = stmt.executeQuery(); rs = stmt.executeQuery();
notifications = new ArrayList<>(); notifications = new ArrayList<>();
while (rs.next()) { while (rs.next()) {
notifications.add(this.getNotification(rs)); notifications.add(NotificationDAOUtil.getNotification(rs));
} }
} catch (SQLException e) { } catch (SQLException e) {
throw new NotificationManagementException( throw new NotificationManagementException(
@ -238,7 +238,7 @@ public abstract class NotificationDAOImpl implements NotificationDAO {
rs = stmt.executeQuery(); rs = stmt.executeQuery();
notifications = new ArrayList<>(); notifications = new ArrayList<>();
while (rs.next()) { while (rs.next()) {
notifications.add(this.getNotification(rs)); notifications.add(NotificationDAOUtil.getNotification(rs));
} }
} catch (SQLException e) { } catch (SQLException e) {
throw new NotificationManagementException( throw new NotificationManagementException(
@ -283,59 +283,4 @@ public abstract class NotificationDAOImpl implements NotificationDAO {
} }
return notificationCountByStatus; return notificationCountByStatus;
} }
@Override
public List<Notification> getNotificationsByStatus(PaginationRequest request, Notification.Status status, int tenantId) throws
NotificationManagementException{
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
List<Notification> notifications = null;
try {
conn = NotificationManagementDAOFactory.getConnection();
String sql = "SELECT n1.NOTIFICATION_ID, n1.DEVICE_ID, n1.OPERATION_ID, n1.STATUS," +
" n1.DESCRIPTION, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM " +
"DM_DEVICE d, DM_DEVICE_TYPE t, (SELECT NOTIFICATION_ID, DEVICE_ID, " +
"OPERATION_ID, STATUS, DESCRIPTION FROM DM_NOTIFICATION WHERE " +
"TENANT_ID = ? AND STATUS = ?) n1 WHERE n1.DEVICE_ID = d.ID AND d.DEVICE_TYPE_ID=t.ID " +
"AND TENANT_ID = ?";
sql = sql + " LIMIT ?,?";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, tenantId);
stmt.setString(2, status.toString());
stmt.setInt(3, tenantId);
int paramIdx = 4;
stmt.setInt(paramIdx++, request.getStartIndex());
stmt.setInt(paramIdx, request.getRowCount());
rs = stmt.executeQuery();
notifications = new ArrayList<>();
while (rs.next()) {
notifications.add(this.getNotification(rs));
}
} catch (SQLException e) {
throw new NotificationManagementException(
"Error occurred while retrieving information of all " +
"notifications by status : " + status, e);
} finally {
NotificationDAOUtil.cleanupResources(stmt, rs);
}
return notifications;
}
private Notification getNotification(ResultSet rs) throws SQLException {
Notification notification = new Notification();
notification.setNotificationId(rs.getInt("NOTIFICATION_ID"));
notification.setOperationId(rs.getInt("OPERATION_ID"));
notification.setDescription(rs.getString("DESCRIPTION"));
notification.setStatus(rs.getString("STATUS"));
return notification;
}
} }

@ -0,0 +1,122 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* you may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.mgt.core.notification.mgt.dao.impl;
import org.wso2.carbon.device.mgt.common.PaginationRequest;
import org.wso2.carbon.device.mgt.common.notification.mgt.Notification;
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException;
import org.wso2.carbon.device.mgt.core.notification.mgt.dao.NotificationManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.notification.mgt.dao.util.NotificationDAOUtil;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
/**
* This class holds the generic implementation of NotificationDAO which can be used to support ANSI db syntax.
*/
public class GenericNotificationDAOImpl extends AbstractNotificationDAOImpl {
@Override
public List<Notification> getAllNotifications(PaginationRequest request, int tenantId) throws
NotificationManagementException {
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
List<Notification> notifications = null;
try {
conn = NotificationManagementDAOFactory.getConnection();
String sql =
"SELECT n1.NOTIFICATION_ID, n1.DEVICE_ID, n1.OPERATION_ID, n1.STATUS, n1.DESCRIPTION," +
" d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, DM_DEVICE_TYPE t, (SELECT " +
"NOTIFICATION_ID, DEVICE_ID, OPERATION_ID, STATUS, DESCRIPTION FROM DM_NOTIFICATION WHERE " +
"TENANT_ID = ?) n1 WHERE n1.DEVICE_ID = d.ID AND d.DEVICE_TYPE_ID=t.ID AND TENANT_ID = ?";
sql = sql + " LIMIT ?,?";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, tenantId);
stmt.setInt(2, tenantId);
int paramIdx = 3;
stmt.setInt(paramIdx++, request.getStartIndex());
stmt.setInt(paramIdx, request.getRowCount());
rs = stmt.executeQuery();
notifications = new ArrayList<>();
while (rs.next()) {
notifications.add(NotificationDAOUtil.getNotification(rs));
}
} catch (SQLException e) {
throw new NotificationManagementException(
"Error occurred while retrieving information of all notifications", e);
} finally {
NotificationDAOUtil.cleanupResources(stmt, rs);
}
return notifications;
}
@Override
public List<Notification> getNotificationsByStatus(PaginationRequest request, Notification.Status status, int tenantId) throws
NotificationManagementException{
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
List<Notification> notifications = null;
try {
conn = NotificationManagementDAOFactory.getConnection();
String sql = "SELECT n1.NOTIFICATION_ID, n1.DEVICE_ID, n1.OPERATION_ID, n1.STATUS," +
" n1.DESCRIPTION, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM " +
"DM_DEVICE d, DM_DEVICE_TYPE t, (SELECT NOTIFICATION_ID, DEVICE_ID, " +
"OPERATION_ID, STATUS, DESCRIPTION FROM DM_NOTIFICATION WHERE " +
"TENANT_ID = ? AND STATUS = ?) n1 WHERE n1.DEVICE_ID = d.ID AND d.DEVICE_TYPE_ID=t.ID " +
"AND TENANT_ID = ?";
sql = sql + " LIMIT ?,?";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, tenantId);
stmt.setString(2, status.toString());
stmt.setInt(3, tenantId);
int paramIdx = 4;
stmt.setInt(paramIdx++, request.getStartIndex());
stmt.setInt(paramIdx, request.getRowCount());
rs = stmt.executeQuery();
notifications = new ArrayList<>();
while (rs.next()) {
notifications.add(NotificationDAOUtil.getNotification(rs));
}
} catch (SQLException e) {
throw new NotificationManagementException(
"Error occurred while retrieving information of all " +
"notifications by status : " + status, e);
} finally {
NotificationDAOUtil.cleanupResources(stmt, rs);
}
return notifications;
}
}

@ -0,0 +1,122 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* you may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.mgt.core.notification.mgt.dao.impl;
import org.wso2.carbon.device.mgt.common.PaginationRequest;
import org.wso2.carbon.device.mgt.common.notification.mgt.Notification;
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException;
import org.wso2.carbon.device.mgt.core.notification.mgt.dao.NotificationManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.notification.mgt.dao.util.NotificationDAOUtil;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
/**
* This class holds the Oracle implementation of NotificationDAO which can be used to support Oracle db syntax.
*/
public class OracleNotificationDAOImpl extends AbstractNotificationDAOImpl {
@Override
public List<Notification> getAllNotifications(PaginationRequest request, int tenantId) throws
NotificationManagementException {
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
List<Notification> notifications = null;
try {
conn = NotificationManagementDAOFactory.getConnection();
String sql =
"SELECT n1.NOTIFICATION_ID, n1.DEVICE_ID, n1.OPERATION_ID, n1.STATUS, n1.DESCRIPTION," +
" d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, DM_DEVICE_TYPE t, (SELECT " +
"NOTIFICATION_ID, DEVICE_ID, OPERATION_ID, STATUS, DESCRIPTION FROM DM_NOTIFICATION WHERE " +
"TENANT_ID = ?) n1 WHERE n1.DEVICE_ID = d.ID AND d.DEVICE_TYPE_ID=t.ID AND TENANT_ID = ?";
sql = sql + " WHERE OFFSET >= ? AND ROWNUM <= ?";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, tenantId);
stmt.setInt(2, tenantId);
int paramIdx = 3;
stmt.setInt(paramIdx++, request.getStartIndex());
stmt.setInt(paramIdx, request.getRowCount());
rs = stmt.executeQuery();
notifications = new ArrayList<>();
while (rs.next()) {
notifications.add(NotificationDAOUtil.getNotification(rs));
}
} catch (SQLException e) {
throw new NotificationManagementException(
"Error occurred while retrieving information of all notifications", e);
} finally {
NotificationDAOUtil.cleanupResources(stmt, rs);
}
return notifications;
}
@Override
public List<Notification> getNotificationsByStatus(PaginationRequest request, Notification.Status status, int tenantId) throws
NotificationManagementException{
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
List<Notification> notifications = null;
try {
conn = NotificationManagementDAOFactory.getConnection();
String sql = "SELECT n1.NOTIFICATION_ID, n1.DEVICE_ID, n1.OPERATION_ID, n1.STATUS," +
" n1.DESCRIPTION, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM " +
"DM_DEVICE d, DM_DEVICE_TYPE t, (SELECT NOTIFICATION_ID, DEVICE_ID, " +
"OPERATION_ID, STATUS, DESCRIPTION FROM DM_NOTIFICATION WHERE " +
"TENANT_ID = ? AND STATUS = ?) n1 WHERE n1.DEVICE_ID = d.ID AND d.DEVICE_TYPE_ID=t.ID " +
"AND TENANT_ID = ?";
sql = sql + " OFFSET >= ? AND ROWNUM <= ?";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, tenantId);
stmt.setString(2, status.toString());
stmt.setInt(3, tenantId);
int paramIdx = 4;
stmt.setInt(paramIdx++, request.getStartIndex());
stmt.setInt(paramIdx, request.getRowCount());
rs = stmt.executeQuery();
notifications = new ArrayList<>();
while (rs.next()) {
notifications.add(NotificationDAOUtil.getNotification(rs));
}
} catch (SQLException e) {
throw new NotificationManagementException(
"Error occurred while retrieving information of all " +
"notifications by status : " + status, e);
} finally {
NotificationDAOUtil.cleanupResources(stmt, rs);
}
return notifications;
}
}

@ -0,0 +1,122 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* you may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.mgt.core.notification.mgt.dao.impl;
import org.wso2.carbon.device.mgt.common.PaginationRequest;
import org.wso2.carbon.device.mgt.common.notification.mgt.Notification;
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException;
import org.wso2.carbon.device.mgt.core.notification.mgt.dao.NotificationManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.notification.mgt.dao.util.NotificationDAOUtil;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
/**
* This class holds the implementation of NotificationDAO which can be used to support PostgreSQL db syntax.
*/
public class PostgreSQLNotificationDAOImpl extends AbstractNotificationDAOImpl {
@Override
public List<Notification> getAllNotifications(PaginationRequest request, int tenantId) throws
NotificationManagementException {
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
List<Notification> notifications = null;
try {
conn = NotificationManagementDAOFactory.getConnection();
String sql =
"SELECT n1.NOTIFICATION_ID, n1.DEVICE_ID, n1.OPERATION_ID, n1.STATUS, n1.DESCRIPTION," +
" d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, DM_DEVICE_TYPE t, (SELECT " +
"NOTIFICATION_ID, DEVICE_ID, OPERATION_ID, STATUS, DESCRIPTION FROM DM_NOTIFICATION WHERE " +
"TENANT_ID = ?) n1 WHERE n1.DEVICE_ID = d.ID AND d.DEVICE_TYPE_ID=t.ID AND TENANT_ID = ?";
sql = sql + " LIMIT ? OFFSET ?";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, tenantId);
stmt.setInt(2, tenantId);
int paramIdx = 3;
stmt.setInt(paramIdx++, request.getRowCount());
stmt.setInt(paramIdx, request.getStartIndex());
rs = stmt.executeQuery();
notifications = new ArrayList<>();
while (rs.next()) {
notifications.add(NotificationDAOUtil.getNotification(rs));
}
} catch (SQLException e) {
throw new NotificationManagementException(
"Error occurred while retrieving information of all notifications", e);
} finally {
NotificationDAOUtil.cleanupResources(stmt, rs);
}
return notifications;
}
@Override
public List<Notification> getNotificationsByStatus(PaginationRequest request, Notification.Status status, int tenantId) throws
NotificationManagementException{
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
List<Notification> notifications = null;
try {
conn = NotificationManagementDAOFactory.getConnection();
String sql = "SELECT n1.NOTIFICATION_ID, n1.DEVICE_ID, n1.OPERATION_ID, n1.STATUS," +
" n1.DESCRIPTION, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM " +
"DM_DEVICE d, DM_DEVICE_TYPE t, (SELECT NOTIFICATION_ID, DEVICE_ID, " +
"OPERATION_ID, STATUS, DESCRIPTION FROM DM_NOTIFICATION WHERE " +
"TENANT_ID = ? AND STATUS = ?) n1 WHERE n1.DEVICE_ID = d.ID AND d.DEVICE_TYPE_ID=t.ID " +
"AND TENANT_ID = ?";
sql = sql + " LIMIT ? OFFSET ?";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, tenantId);
stmt.setString(2, status.toString());
stmt.setInt(3, tenantId);
int paramIdx = 4;
stmt.setInt(paramIdx++, request.getRowCount());
stmt.setInt(paramIdx, request.getStartIndex());
rs = stmt.executeQuery();
notifications = new ArrayList<>();
while (rs.next()) {
notifications.add(NotificationDAOUtil.getNotification(rs));
}
} catch (SQLException e) {
throw new NotificationManagementException(
"Error occurred while retrieving information of all " +
"notifications by status : " + status, e);
} finally {
NotificationDAOUtil.cleanupResources(stmt, rs);
}
return notifications;
}
}

@ -0,0 +1,122 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* you may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.mgt.core.notification.mgt.dao.impl;
import org.wso2.carbon.device.mgt.common.PaginationRequest;
import org.wso2.carbon.device.mgt.common.notification.mgt.Notification;
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException;
import org.wso2.carbon.device.mgt.core.notification.mgt.dao.NotificationManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.notification.mgt.dao.util.NotificationDAOUtil;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
/**
* This class holds the implementation of NotificationDAO which can be used to support SQLServer db syntax.
*/
public class SQLServerNotificationDAOImpl extends AbstractNotificationDAOImpl {
@Override
public List<Notification> getAllNotifications(PaginationRequest request, int tenantId) throws
NotificationManagementException {
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
List<Notification> notifications = null;
try {
conn = NotificationManagementDAOFactory.getConnection();
String sql =
"SELECT n1.NOTIFICATION_ID, n1.DEVICE_ID, n1.OPERATION_ID, n1.STATUS, n1.DESCRIPTION," +
" d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, DM_DEVICE_TYPE t, (SELECT " +
"NOTIFICATION_ID, DEVICE_ID, OPERATION_ID, STATUS, DESCRIPTION FROM DM_NOTIFICATION WHERE " +
"TENANT_ID = ?) n1 WHERE n1.DEVICE_ID = d.ID AND d.DEVICE_TYPE_ID=t.ID AND TENANT_ID = ?";
sql = sql + " OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, tenantId);
stmt.setInt(2, tenantId);
int paramIdx = 3;
stmt.setInt(paramIdx++, request.getStartIndex());
stmt.setInt(paramIdx, request.getRowCount());
rs = stmt.executeQuery();
notifications = new ArrayList<>();
while (rs.next()) {
notifications.add(NotificationDAOUtil.getNotification(rs));
}
} catch (SQLException e) {
throw new NotificationManagementException(
"Error occurred while retrieving information of all notifications", e);
} finally {
NotificationDAOUtil.cleanupResources(stmt, rs);
}
return notifications;
}
@Override
public List<Notification> getNotificationsByStatus(PaginationRequest request, Notification.Status status, int tenantId) throws
NotificationManagementException{
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
List<Notification> notifications = null;
try {
conn = NotificationManagementDAOFactory.getConnection();
String sql = "SELECT n1.NOTIFICATION_ID, n1.DEVICE_ID, n1.OPERATION_ID, n1.STATUS," +
" n1.DESCRIPTION, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM " +
"DM_DEVICE d, DM_DEVICE_TYPE t, (SELECT NOTIFICATION_ID, DEVICE_ID, " +
"OPERATION_ID, STATUS, DESCRIPTION FROM DM_NOTIFICATION WHERE " +
"TENANT_ID = ? AND STATUS = ?) n1 WHERE n1.DEVICE_ID = d.ID AND d.DEVICE_TYPE_ID=t.ID " +
"AND TENANT_ID = ?";
sql = sql + " OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, tenantId);
stmt.setString(2, status.toString());
stmt.setInt(3, tenantId);
int paramIdx = 4;
stmt.setInt(paramIdx++, request.getStartIndex());
stmt.setInt(paramIdx, request.getRowCount());
rs = stmt.executeQuery();
notifications = new ArrayList<>();
while (rs.next()) {
notifications.add(NotificationDAOUtil.getNotification(rs));
}
} catch (SQLException e) {
throw new NotificationManagementException(
"Error occurred while retrieving information of all " +
"notifications by status : " + status, e);
} finally {
NotificationDAOUtil.cleanupResources(stmt, rs);
}
return notifications;
}
}

@ -21,6 +21,7 @@ package org.wso2.carbon.device.mgt.core.notification.mgt.dao.util;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.device.mgt.common.notification.mgt.Notification;
import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException; import org.wso2.carbon.device.mgt.common.notification.mgt.NotificationManagementException;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
import org.wso2.carbon.user.api.UserStoreException; import org.wso2.carbon.user.api.UserStoreException;
@ -123,4 +124,13 @@ public class NotificationDAOUtil {
throw new RuntimeException("Error in looking up data source: " + e.getMessage(), e); throw new RuntimeException("Error in looking up data source: " + e.getMessage(), e);
} }
} }
public static Notification getNotification(ResultSet rs) throws SQLException {
Notification notification = new Notification();
notification.setNotificationId(rs.getInt("NOTIFICATION_ID"));
notification.setOperationId(rs.getInt("OPERATION_ID"));
notification.setDescription(rs.getString("DESCRIPTION"));
notification.setStatus(rs.getString("STATUS"));
return notification;
}
} }

@ -46,8 +46,8 @@ public class PostgreSQLOperationDAOImpl extends GenericOperationDAOImpl {
List<Operation> operations = new ArrayList<Operation>(); List<Operation> operations = new ArrayList<Operation>();
try { try {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, " + String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, " +
"OPERATION_CODE, om.STATUS FROM DM_OPERATION o " + "o.OPERATION_CODE, om.STATUS FROM DM_OPERATION o " +
"INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " + "INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " +
"WHERE dm.ENROLMENT_ID = ?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP DESC LIMIT ? OFFSET ?"; "WHERE dm.ENROLMENT_ID = ?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP DESC LIMIT ? OFFSET ?";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
@ -72,7 +72,7 @@ public class PostgreSQLOperationDAOImpl extends GenericOperationDAOImpl {
} }
} catch (SQLException e) { } catch (SQLException e) {
throw new OperationManagementDAOException("SQL error occurred while retrieving the operation " + throw new OperationManagementDAOException("SQL error occurred while retrieving the operation " +
"available for the device'" + enrolmentId + "' with status '", e); "available for the device'" + enrolmentId, e);
} finally { } finally {
OperationManagementDAOUtil.cleanupResources(stmt, rs); OperationManagementDAOUtil.cleanupResources(stmt, rs);
} }
@ -89,7 +89,7 @@ public class PostgreSQLOperationDAOImpl extends GenericOperationDAOImpl {
List<Operation> operations = new ArrayList<Operation>(); List<Operation> operations = new ArrayList<Operation>();
try { try {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE " + String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.OPERATION_CODE " +
"FROM DM_OPERATION o " + "FROM DM_OPERATION o " +
"INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " + "INNER JOIN (SELECT * FROM DM_ENROLMENT_OP_MAPPING dm " +
"WHERE dm.ENROLMENT_ID = ? AND dm.STATUS = ?) om ON o.ID = om.OPERATION_ID ORDER BY " + "WHERE dm.ENROLMENT_ID = ? AND dm.STATUS = ?) om ON o.ID = om.OPERATION_ID ORDER BY " +

Loading…
Cancel
Save