|
|
@ -53,7 +53,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|
|
|
String sql = "INSERT INTO DM_DEVICE(DESCRIPTION, NAME, DEVICE_TYPE_ID, DEVICE_IDENTIFICATION, " +
|
|
|
|
String sql = "INSERT INTO DM_DEVICE(DESCRIPTION, NAME, DEVICE_TYPE_ID, DEVICE_IDENTIFICATION, " +
|
|
|
|
"LAST_UPDATED_TIMESTAMP, TENANT_ID) " +
|
|
|
|
"LAST_UPDATED_TIMESTAMP, TENANT_ID) " +
|
|
|
|
"VALUES (?, ?, ?, ?, ?, ?)";
|
|
|
|
"VALUES (?, ?, ?, ?, ?, ?)";
|
|
|
|
stmt = conn.prepareStatement(sql, new String[]{"id"});
|
|
|
|
stmt = conn.prepareStatement(sql, new String[] {"id"});
|
|
|
|
stmt.setString(1, device.getDescription());
|
|
|
|
stmt.setString(1, device.getDescription());
|
|
|
|
stmt.setString(2, device.getName());
|
|
|
|
stmt.setString(2, device.getName());
|
|
|
|
stmt.setInt(3, typeId);
|
|
|
|
stmt.setInt(3, typeId);
|
|
|
@ -85,7 +85,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|
|
|
String sql = "UPDATE DM_DEVICE SET NAME = ?, DESCRIPTION = ?, LAST_UPDATED_TIMESTAMP = ? " +
|
|
|
|
String sql = "UPDATE DM_DEVICE SET NAME = ?, DESCRIPTION = ?, LAST_UPDATED_TIMESTAMP = ? " +
|
|
|
|
"WHERE DEVICE_TYPE_ID = (SELECT ID FROM DM_DEVICE_TYPE WHERE NAME = ? AND PROVIDER_TENANT_ID = ?) " +
|
|
|
|
"WHERE DEVICE_TYPE_ID = (SELECT ID FROM DM_DEVICE_TYPE WHERE NAME = ? AND PROVIDER_TENANT_ID = ?) " +
|
|
|
|
"AND DEVICE_IDENTIFICATION = ? AND TENANT_ID = ?";
|
|
|
|
"AND DEVICE_IDENTIFICATION = ? AND TENANT_ID = ?";
|
|
|
|
stmt = conn.prepareStatement(sql, new String[]{"id"});
|
|
|
|
stmt = conn.prepareStatement(sql, new String[] {"id"});
|
|
|
|
stmt.setString(1, device.getName());
|
|
|
|
stmt.setString(1, device.getName());
|
|
|
|
stmt.setString(2, device.getDescription());
|
|
|
|
stmt.setString(2, device.getDescription());
|
|
|
|
stmt.setTimestamp(3, new Timestamp(new Date().getTime()));
|
|
|
|
stmt.setTimestamp(3, new Timestamp(new Date().getTime()));
|
|
|
@ -142,7 +142,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Device getDevice(DeviceIdentifier deviceIdentifier, Date since, int tenantId)
|
|
|
|
public Device getDevice(DeviceIdentifier deviceIdentifier, Date since, int tenantId)
|
|
|
|
throws DeviceManagementDAOException {
|
|
|
|
throws DeviceManagementDAOException {
|
|
|
|
Connection conn;
|
|
|
|
Connection conn;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
ResultSet rs = null;
|
|
|
@ -150,11 +150,11 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getConnection();
|
|
|
|
conn = this.getConnection();
|
|
|
|
String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
|
|
|
String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
|
|
|
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
|
|
|
|
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
|
|
|
|
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, d.NAME, " +
|
|
|
|
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, d.NAME, " +
|
|
|
|
"t.NAME AS DEVICE_TYPE, d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, DM_DEVICE_TYPE t, DM_DEVICE_DETAIL dt " +
|
|
|
|
"t.NAME AS DEVICE_TYPE, d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, DM_DEVICE_TYPE t, DM_DEVICE_DETAIL dt " +
|
|
|
|
"WHERE t.NAME = ? AND d.DEVICE_IDENTIFICATION = ? AND d.TENANT_ID = ? AND dt.DEVICE_ID = d.ID " +
|
|
|
|
"WHERE t.NAME = ? AND d.DEVICE_IDENTIFICATION = ? AND d.TENANT_ID = ? AND dt.DEVICE_ID = d.ID " +
|
|
|
|
"AND dt.UPDATE_TIMESTAMP > ?) d1 WHERE d1.ID = e.DEVICE_ID AND TENANT_ID = ?";
|
|
|
|
"AND dt.UPDATE_TIMESTAMP > ?) d1 WHERE d1.ID = e.DEVICE_ID AND TENANT_ID = ?" ;
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
int paramIdx = 1;
|
|
|
|
int paramIdx = 1;
|
|
|
|
stmt.setString(paramIdx++, deviceIdentifier.getType());
|
|
|
|
stmt.setString(paramIdx++, deviceIdentifier.getType());
|
|
|
@ -168,7 +168,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while listing device for type " +
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while listing device for type " +
|
|
|
|
"'" + deviceIdentifier.getType() + "'", e);
|
|
|
|
"'" + deviceIdentifier.getType() + "'", e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -177,7 +177,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Device getDevice(DeviceIdentifier deviceIdentifier, EnrolmentInfo.Status status, int tenantId) throws
|
|
|
|
public Device getDevice(DeviceIdentifier deviceIdentifier, EnrolmentInfo.Status status, int tenantId) throws
|
|
|
|
DeviceManagementDAOException {
|
|
|
|
DeviceManagementDAOException {
|
|
|
|
Connection conn;
|
|
|
|
Connection conn;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
ResultSet rs = null;
|
|
|
@ -185,11 +185,11 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getConnection();
|
|
|
|
conn = this.getConnection();
|
|
|
|
String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
|
|
|
String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
|
|
|
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
|
|
|
|
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
|
|
|
|
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, d.NAME, " +
|
|
|
|
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, d.NAME, " +
|
|
|
|
"t.NAME AS DEVICE_TYPE, d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE " +
|
|
|
|
"t.NAME AS DEVICE_TYPE, d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE " +
|
|
|
|
"t.NAME = ? AND d.DEVICE_IDENTIFICATION = ? AND d.TENANT_ID = ?) d1 WHERE d1.ID = e.DEVICE_ID " +
|
|
|
|
"t.NAME = ? AND d.DEVICE_IDENTIFICATION = ? AND d.TENANT_ID = ?) d1 WHERE d1.ID = e.DEVICE_ID " +
|
|
|
|
"AND TENANT_ID = ? AND e.STATUS = ?";
|
|
|
|
"AND TENANT_ID = ? AND e.STATUS = ?";
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt.setString(1, deviceIdentifier.getType());
|
|
|
|
stmt.setString(1, deviceIdentifier.getType());
|
|
|
|
stmt.setString(2, deviceIdentifier.getId());
|
|
|
|
stmt.setString(2, deviceIdentifier.getId());
|
|
|
@ -202,7 +202,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while listing devices for type " +
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while listing devices for type " +
|
|
|
|
"'" + deviceIdentifier.getType() + "'", e);
|
|
|
|
"'" + deviceIdentifier.getType() + "'", e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -249,11 +249,11 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getConnection();
|
|
|
|
conn = this.getConnection();
|
|
|
|
String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
|
|
|
String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
|
|
|
|
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
|
|
|
|
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
|
|
|
|
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, d.NAME, " +
|
|
|
|
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, d.NAME, " +
|
|
|
|
"t.NAME AS DEVICE_TYPE, d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE " +
|
|
|
|
"t.NAME AS DEVICE_TYPE, d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE " +
|
|
|
|
"d.ID = ? AND d.TENANT_ID = ?) d1 WHERE d1.ID = e.DEVICE_ID " +
|
|
|
|
"d.ID = ? AND d.TENANT_ID = ?) d1 WHERE d1.ID = e.DEVICE_ID " +
|
|
|
|
"AND TENANT_ID = ?";
|
|
|
|
"AND TENANT_ID = ?";
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt.setInt(1, deviceId);
|
|
|
|
stmt.setInt(1, deviceId);
|
|
|
|
stmt.setInt(2, tenantId);
|
|
|
|
stmt.setInt(2, tenantId);
|
|
|
@ -264,7 +264,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while retrieving device for id " +
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while retrieving device for id " +
|
|
|
|
"'" + deviceId + "'", e);
|
|
|
|
"'" + deviceId + "'", e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -346,11 +346,11 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getConnection();
|
|
|
|
conn = this.getConnection();
|
|
|
|
String sql = "SELECT e1.OWNER, e1.OWNERSHIP, e1.ENROLMENT_ID, e1.DEVICE_ID, e1.STATUS, e1.DATE_OF_LAST_UPDATE," +
|
|
|
|
String sql = "SELECT e1.OWNER, e1.OWNERSHIP, e1.ENROLMENT_ID, e1.DEVICE_ID, e1.STATUS, e1.DATE_OF_LAST_UPDATE," +
|
|
|
|
" e1.DATE_OF_ENROLMENT, d.DESCRIPTION, d.NAME AS DEVICE_NAME, d.DEVICE_IDENTIFICATION, t.NAME " +
|
|
|
|
" e1.DATE_OF_ENROLMENT, d.DESCRIPTION, d.NAME AS DEVICE_NAME, d.DEVICE_IDENTIFICATION, t.NAME " +
|
|
|
|
"AS DEVICE_TYPE FROM DM_DEVICE d, (SELECT e.OWNER, e.OWNERSHIP, e.ID AS ENROLMENT_ID, " +
|
|
|
|
"AS DEVICE_TYPE FROM DM_DEVICE d, (SELECT e.OWNER, e.OWNERSHIP, e.ID AS ENROLMENT_ID, " +
|
|
|
|
"e.DEVICE_ID, e.STATUS, e.DATE_OF_LAST_UPDATE, e.DATE_OF_ENROLMENT FROM DM_ENROLMENT e WHERE " +
|
|
|
|
"e.DEVICE_ID, e.STATUS, e.DATE_OF_LAST_UPDATE, e.DATE_OF_ENROLMENT FROM DM_ENROLMENT e WHERE " +
|
|
|
|
"e.TENANT_ID = ? AND e.OWNER = ?) e1, DM_DEVICE_TYPE t WHERE d.ID = e1.DEVICE_ID " +
|
|
|
|
"e.TENANT_ID = ? AND e.OWNER = ?) e1, DM_DEVICE_TYPE t WHERE d.ID = e1.DEVICE_ID " +
|
|
|
|
"AND t.ID = d.DEVICE_TYPE_ID";
|
|
|
|
"AND t.ID = d.DEVICE_TYPE_ID";
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt.setInt(1, tenantId);
|
|
|
|
stmt.setInt(1, tenantId);
|
|
|
|
stmt.setString(2, username);
|
|
|
|
stmt.setString(2, username);
|
|
|
@ -422,8 +422,8 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getConnection();
|
|
|
|
conn = this.getConnection();
|
|
|
|
String sql = "SELECT COUNT(d1.DEVICE_ID) AS DEVICE_COUNT FROM DM_ENROLMENT e, (SELECT d.ID AS DEVICE_ID FROM " +
|
|
|
|
String sql = "SELECT COUNT(d1.DEVICE_ID) AS DEVICE_COUNT FROM DM_ENROLMENT e, (SELECT d.ID AS DEVICE_ID FROM " +
|
|
|
|
"DM_DEVICE d, DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?) d1 WHERE " +
|
|
|
|
"DM_DEVICE d, DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?) d1 WHERE " +
|
|
|
|
"d1.DEVICE_ID = e.DEVICE_ID AND e.OWNER = ? AND TENANT_ID = ?";
|
|
|
|
"d1.DEVICE_ID = e.DEVICE_ID AND e.OWNER = ? AND TENANT_ID = ?";
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt.setInt(1, tenantId);
|
|
|
|
stmt.setInt(1, tenantId);
|
|
|
|
stmt.setString(2, username);
|
|
|
|
stmt.setString(2, username);
|
|
|
@ -455,8 +455,8 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getConnection();
|
|
|
|
conn = this.getConnection();
|
|
|
|
String sql = "SELECT COUNT(d1.DEVICE_ID) AS DEVICE_COUNT FROM DM_ENROLMENT e, (SELECT d.ID AS DEVICE_ID FROM " +
|
|
|
|
String sql = "SELECT COUNT(d1.DEVICE_ID) AS DEVICE_COUNT FROM DM_ENROLMENT e, (SELECT d.ID AS DEVICE_ID FROM " +
|
|
|
|
"DM_DEVICE d, DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?) d1 WHERE " +
|
|
|
|
"DM_DEVICE d, DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?) d1 WHERE " +
|
|
|
|
"d1.DEVICE_ID = e.DEVICE_ID AND TENANT_ID = ?";
|
|
|
|
"d1.DEVICE_ID = e.DEVICE_ID AND TENANT_ID = ?";
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt.setInt(1, tenantId);
|
|
|
|
stmt.setInt(1, tenantId);
|
|
|
|
stmt.setInt(2, tenantId);
|
|
|
|
stmt.setInt(2, tenantId);
|
|
|
@ -493,7 +493,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getConnection();
|
|
|
|
conn = this.getConnection();
|
|
|
|
String sql = "SELECT COUNT(d1.ID) AS DEVICE_COUNT FROM DM_ENROLMENT e, (SELECT d.ID, d.NAME, d.DEVICE_IDENTIFICATION, " +
|
|
|
|
String sql = "SELECT COUNT(d1.ID) AS DEVICE_COUNT FROM DM_ENROLMENT e, (SELECT d.ID, d.NAME, d.DEVICE_IDENTIFICATION, " +
|
|
|
|
"t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, DM_DEVICE_TYPE t";
|
|
|
|
"t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, DM_DEVICE_TYPE t";
|
|
|
|
|
|
|
|
|
|
|
|
//Add query for last updated timestamp
|
|
|
|
//Add query for last updated timestamp
|
|
|
|
if (since != null) {
|
|
|
|
if (since != null) {
|
|
|
@ -561,7 +561,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while retrieving information of all " +
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while retrieving information of all " +
|
|
|
|
"registered devices", e);
|
|
|
|
"registered devices", e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -577,8 +577,8 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getConnection();
|
|
|
|
conn = this.getConnection();
|
|
|
|
String sql = "SELECT COUNT(d1.ID) AS DEVICE_COUNT FROM DM_ENROLMENT e, (SELECT d.ID FROM DM_DEVICE d, " +
|
|
|
|
String sql = "SELECT COUNT(d1.ID) AS DEVICE_COUNT FROM DM_ENROLMENT e, (SELECT d.ID FROM DM_DEVICE d, " +
|
|
|
|
"DM_DEVICE_TYPE t WHERE DEVICE_TYPE_ID = t.ID AND t.NAME = ? " +
|
|
|
|
"DM_DEVICE_TYPE t WHERE DEVICE_TYPE_ID = t.ID AND t.NAME = ? " +
|
|
|
|
"AND d.TENANT_ID = ?) d1 WHERE d1.ID = e.DEVICE_ID AND TENANT_ID = ?";
|
|
|
|
"AND d.TENANT_ID = ?) d1 WHERE d1.ID = e.DEVICE_ID AND TENANT_ID = ?";
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt.setString(1, type);
|
|
|
|
stmt.setString(1, type);
|
|
|
|
stmt.setInt(2, tenantId);
|
|
|
|
stmt.setInt(2, tenantId);
|
|
|
@ -603,8 +603,8 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getConnection();
|
|
|
|
conn = this.getConnection();
|
|
|
|
String sql = "SELECT COUNT(e1.DEVICE_ID) AS DEVICE_COUNT FROM DM_DEVICE d, (SELECT e.DEVICE_ID " +
|
|
|
|
String sql = "SELECT COUNT(e1.DEVICE_ID) AS DEVICE_COUNT FROM DM_DEVICE d, (SELECT e.DEVICE_ID " +
|
|
|
|
"FROM DM_ENROLMENT e WHERE e.TENANT_ID = ? AND e.OWNER = ?) " +
|
|
|
|
"FROM DM_ENROLMENT e WHERE e.TENANT_ID = ? AND e.OWNER = ?) " +
|
|
|
|
"e1, DM_DEVICE_TYPE t WHERE d.ID = e1.DEVICE_ID AND t.ID = d.DEVICE_TYPE_ID";
|
|
|
|
"e1, DM_DEVICE_TYPE t WHERE d.ID = e1.DEVICE_ID AND t.ID = d.DEVICE_TYPE_ID";
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt.setInt(1, tenantId);
|
|
|
|
stmt.setInt(1, tenantId);
|
|
|
|
stmt.setString(2, username);
|
|
|
|
stmt.setString(2, username);
|
|
|
@ -615,7 +615,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while fetching the list of devices belongs to '" +
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while fetching the list of devices belongs to '" +
|
|
|
|
username + "'", e);
|
|
|
|
username + "'", e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -630,8 +630,8 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getConnection();
|
|
|
|
conn = this.getConnection();
|
|
|
|
String sql = "SELECT COUNT(d1.ID) AS DEVICE_COUNT FROM DM_ENROLMENT e, (SELECT d.ID FROM DM_DEVICE d, " +
|
|
|
|
String sql = "SELECT COUNT(d1.ID) AS DEVICE_COUNT FROM DM_ENROLMENT e, (SELECT d.ID FROM DM_DEVICE d, " +
|
|
|
|
"DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.NAME LIKE ? AND d.TENANT_ID = ?) d1 " +
|
|
|
|
"DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.NAME LIKE ? AND d.TENANT_ID = ?) d1 " +
|
|
|
|
"WHERE d1.ID = e.DEVICE_ID AND TENANT_ID = ?";
|
|
|
|
"WHERE d1.ID = e.DEVICE_ID AND TENANT_ID = ?";
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt.setString(1, deviceName + "%");
|
|
|
|
stmt.setString(1, deviceName + "%");
|
|
|
|
stmt.setInt(2, tenantId);
|
|
|
|
stmt.setInt(2, tenantId);
|
|
|
@ -643,7 +643,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while fetching the device count that matches " +
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while fetching the device count that matches " +
|
|
|
|
"'" + deviceName + "'", e);
|
|
|
|
"'" + deviceName + "'", e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -658,8 +658,8 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getConnection();
|
|
|
|
conn = this.getConnection();
|
|
|
|
String sql = "SELECT COUNT(d.ID) AS DEVICE_COUNT FROM (SELECT e.DEVICE_ID FROM DM_ENROLMENT e WHERE " +
|
|
|
|
String sql = "SELECT COUNT(d.ID) AS DEVICE_COUNT FROM (SELECT e.DEVICE_ID FROM DM_ENROLMENT e WHERE " +
|
|
|
|
"TENANT_ID = ? AND OWNERSHIP = ?) e, DM_DEVICE d, " +
|
|
|
|
"TENANT_ID = ? AND OWNERSHIP = ?) e, DM_DEVICE d, " +
|
|
|
|
"DM_DEVICE_TYPE t WHERE d.ID = e.DEVICE_ID AND d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?";
|
|
|
|
"DM_DEVICE_TYPE t WHERE d.ID = e.DEVICE_ID AND d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?";
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt.setInt(1, tenantId);
|
|
|
|
stmt.setInt(1, tenantId);
|
|
|
|
stmt.setString(2, ownerShip);
|
|
|
|
stmt.setString(2, ownerShip);
|
|
|
@ -671,7 +671,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while fetching the list of devices that matches to ownership " +
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while fetching the list of devices that matches to ownership " +
|
|
|
|
"'" + ownerShip + "'", e);
|
|
|
|
"'" + ownerShip + "'", e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -686,8 +686,8 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getConnection();
|
|
|
|
conn = this.getConnection();
|
|
|
|
String sql = "SELECT COUNT(d.ID) AS DEVICE_COUNT FROM (SELECT e.DEVICE_ID FROM DM_ENROLMENT e WHERE " +
|
|
|
|
String sql = "SELECT COUNT(d.ID) AS DEVICE_COUNT FROM (SELECT e.DEVICE_ID FROM DM_ENROLMENT e WHERE " +
|
|
|
|
"TENANT_ID = ? AND STATUS = ?) e, DM_DEVICE d, " +
|
|
|
|
"TENANT_ID = ? AND STATUS = ?) e, DM_DEVICE d, " +
|
|
|
|
"DM_DEVICE_TYPE t WHERE d.ID = e.DEVICE_ID AND d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?";
|
|
|
|
"DM_DEVICE_TYPE t WHERE d.ID = e.DEVICE_ID AND d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?";
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt.setInt(1, tenantId);
|
|
|
|
stmt.setInt(1, tenantId);
|
|
|
|
stmt.setString(2, status);
|
|
|
|
stmt.setString(2, status);
|
|
|
@ -699,7 +699,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while fetching the list of devices that matches to status " +
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while fetching the list of devices that matches to status " +
|
|
|
|
"'" + status + "'", e);
|
|
|
|
"'" + status + "'", e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -716,7 +716,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|
|
|
conn = this.getConnection();
|
|
|
|
conn = this.getConnection();
|
|
|
|
String sql = "INSERT INTO DM_ENROLMENT(DEVICE_ID, OWNER, OWNERSHIP, STATUS,DATE_OF_ENROLMENT, " +
|
|
|
|
String sql = "INSERT INTO DM_ENROLMENT(DEVICE_ID, OWNER, OWNERSHIP, STATUS,DATE_OF_ENROLMENT, " +
|
|
|
|
"DATE_OF_LAST_UPDATE, TENANT_ID) VALUES(?, ?, ?, ?, ?, ?, ?)";
|
|
|
|
"DATE_OF_LAST_UPDATE, TENANT_ID) VALUES(?, ?, ?, ?, ?, ?, ?)";
|
|
|
|
stmt = conn.prepareStatement(sql, new String[]{"id"});
|
|
|
|
stmt = conn.prepareStatement(sql, new String[] {"id"});
|
|
|
|
stmt.setInt(1, device.getId());
|
|
|
|
stmt.setInt(1, device.getId());
|
|
|
|
stmt.setString(2, device.getEnrolmentInfo().getOwner());
|
|
|
|
stmt.setString(2, device.getEnrolmentInfo().getOwner());
|
|
|
|
stmt.setString(3, device.getEnrolmentInfo().getOwnership().toString());
|
|
|
|
stmt.setString(3, device.getEnrolmentInfo().getOwnership().toString());
|
|
|
@ -837,10 +837,10 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getConnection();
|
|
|
|
conn = this.getConnection();
|
|
|
|
String sql = "SELECT ID AS ENROLMENT_ID, DEVICE_ID, OWNER, OWNERSHIP, STATUS, DATE_OF_ENROLMENT, " +
|
|
|
|
String sql = "SELECT ID AS ENROLMENT_ID, DEVICE_ID, OWNER, OWNERSHIP, STATUS, DATE_OF_ENROLMENT, " +
|
|
|
|
"DATE_OF_LAST_UPDATE, TENANT_ID FROM DM_ENROLMENT WHERE DEVICE_ID = (SELECT d.ID " +
|
|
|
|
"DATE_OF_LAST_UPDATE, TENANT_ID FROM DM_ENROLMENT WHERE DEVICE_ID = (SELECT d.ID " +
|
|
|
|
"FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID " +
|
|
|
|
"FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID " +
|
|
|
|
"AND d.DEVICE_IDENTIFICATION = ? AND t.NAME = ? AND d.TENANT_ID = ?) " +
|
|
|
|
"AND d.DEVICE_IDENTIFICATION = ? AND t.NAME = ? AND d.TENANT_ID = ?) " +
|
|
|
|
"AND TENANT_ID = ?";
|
|
|
|
"AND TENANT_ID = ?";
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt.setString(1, deviceId.getId());
|
|
|
|
stmt.setString(1, deviceId.getId());
|
|
|
|
stmt.setString(2, deviceId.getType());
|
|
|
|
stmt.setString(2, deviceId.getType());
|
|
|
@ -853,7 +853,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|
|
|
return enrolmentInfo;
|
|
|
|
return enrolmentInfo;
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while retrieving the enrolment " +
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while retrieving the enrolment " +
|
|
|
|
"of device '" + deviceId + "'", e);
|
|
|
|
"of device '" + deviceId + "'", e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -868,10 +868,10 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getConnection();
|
|
|
|
conn = this.getConnection();
|
|
|
|
String sql = "SELECT ID AS ENROLMENT_ID, DEVICE_ID, OWNER, OWNERSHIP, STATUS, DATE_OF_ENROLMENT, " +
|
|
|
|
String sql = "SELECT ID AS ENROLMENT_ID, DEVICE_ID, OWNER, OWNERSHIP, STATUS, DATE_OF_ENROLMENT, " +
|
|
|
|
"DATE_OF_LAST_UPDATE, TENANT_ID FROM DM_ENROLMENT WHERE DEVICE_ID = (SELECT d.ID " +
|
|
|
|
"DATE_OF_LAST_UPDATE, TENANT_ID FROM DM_ENROLMENT WHERE DEVICE_ID = (SELECT d.ID " +
|
|
|
|
"FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID " +
|
|
|
|
"FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID " +
|
|
|
|
"AND d.DEVICE_IDENTIFICATION = ? AND t.NAME = ? AND d.TENANT_ID = ?) " +
|
|
|
|
"AND d.DEVICE_IDENTIFICATION = ? AND t.NAME = ? AND d.TENANT_ID = ?) " +
|
|
|
|
"AND TENANT_ID = ? AND STATUS in ('ACTIVE','UNREACHABLE','INACTIVE')";
|
|
|
|
"AND TENANT_ID = ? AND STATUS in ('ACTIVE','UNREACHABLE','INACTIVE')";
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt.setString(1, deviceId.getId());
|
|
|
|
stmt.setString(1, deviceId.getId());
|
|
|
|
stmt.setString(2, deviceId.getType());
|
|
|
|
stmt.setString(2, deviceId.getType());
|
|
|
@ -884,8 +884,8 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|
|
|
return enrolmentInfo;
|
|
|
|
return enrolmentInfo;
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while retrieving the enrolment " +
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while retrieving the enrolment " +
|
|
|
|
"information of device '" + deviceId.getId() + "' of type : "
|
|
|
|
"information of device '" + deviceId.getId() + "' of type : "
|
|
|
|
+ deviceId.getType(), e);
|
|
|
|
+ deviceId.getType(), e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -899,8 +899,8 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getConnection();
|
|
|
|
conn = this.getConnection();
|
|
|
|
String sql = "SELECT e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID FROM DM_DEVICE d, DM_DEVICE_TYPE t " +
|
|
|
|
String sql = "SELECT e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID FROM DM_DEVICE d, DM_DEVICE_TYPE t " +
|
|
|
|
"WHERE d.DEVICE_TYPE_ID = t.ID AND d.DEVICE_IDENTIFICATION = ? AND t.NAME = ? AND d.TENANT_ID = ?) dtm " +
|
|
|
|
"WHERE d.DEVICE_TYPE_ID = t.ID AND d.DEVICE_IDENTIFICATION = ? AND t.NAME = ? AND d.TENANT_ID = ?) dtm " +
|
|
|
|
"WHERE e.DEVICE_ID = dtm.ID AND e.STATUS = ? AND e.TENANT_ID = ?;";
|
|
|
|
"WHERE e.DEVICE_ID = dtm.ID AND e.STATUS = ? AND e.TENANT_ID = ?;";
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt.setString(1, deviceId.getId());
|
|
|
|
stmt.setString(1, deviceId.getId());
|
|
|
|
stmt.setString(2, deviceId.getType());
|
|
|
|
stmt.setString(2, deviceId.getType());
|
|
|
@ -1029,7 +1029,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param timestamp Timestamp in long, after which the devices have been updated.
|
|
|
|
* @param timestamp Timestamp in long, after which the devices have been updated.
|
|
|
|
* @param tenantId Tenant id of the currently logged in user.
|
|
|
|
* @param tenantId Tenant id of the currently logged in user.
|
|
|
|
* @return A collection of devices that have been updated after the provided timestamp
|
|
|
|
* @return A collection of devices that have been updated after the provided timestamp
|
|
|
|
* @throws DeviceManagementDAOException
|
|
|
|
* @throws DeviceManagementDAOException
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public List<Device> getDevices(long timestamp, int tenantId) throws DeviceManagementDAOException {
|
|
|
|
public List<Device> getDevices(long timestamp, int tenantId) throws DeviceManagementDAOException {
|
|
|
@ -1084,5 +1084,4 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
|
|
|
return tenants;
|
|
|
|
return tenants;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|