@ -119,13 +119,15 @@ public class DeviceDAOImpl implements DeviceDAO {
try{
try{
conn=this.getConnection();
conn=this.getConnection();
Stringsql=
Stringsql=
"SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME AS DEVICE_NAME, "+
"SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, "+
"t.NAME AS DEVICE_TYPE_NAME, d.DEVICE_IDENTIFICATION, d.TENANT_ID FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE "+
"e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, e.DATE_OF_ENROLMENT FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, d.NAME, "+
"t.NAME = ? AND d.DEVICE_IDENTIFICATION = ? AND d.TENANT_ID = ?";
"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.DEVICE_ID = e.DEVICE_ID AND TENANT_ID = ?";
stmt=conn.prepareStatement(sql);
stmt=conn.prepareStatement(sql);
stmt.setString(1,deviceId.getType());
stmt.setString(1,deviceId.getType());
stmt.setString(2,deviceId.getId());
stmt.setString(2,deviceId.getId());
stmt.setInt(3,tenantId);
stmt.setInt(3,tenantId);
stmt.setInt(4,tenantId);
rs=stmt.executeQuery();
rs=stmt.executeQuery();
if(rs.next()){
if(rs.next()){
device=this.loadDevice(rs);
device=this.loadDevice(rs);
@ -147,11 +149,13 @@ public class DeviceDAOImpl implements DeviceDAO {
List<Device>devices=null;
List<Device>devices=null;
try{
try{
conn=this.getConnection();
conn=this.getConnection();
Stringsql="SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME AS DEVICE_NAME, d.DEVICE_TYPE_ID, "+
Stringsql="SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, "+
"d.DEVICE_IDENTIFICATION, d.TENANT_ID, t.NAME AS DEVICE_TYPE_NAME FROM DM_DEVICE d, DEVICE_TYPE t "+
"e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, e.DATE_OF_ENROLMENT FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, d.NAME,"+
"WHERE d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ? ";
"d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, 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 = ?";
stmt=conn.prepareStatement(sql);
stmt=conn.prepareStatement(sql);
stmt.setInt(1,tenantId);
stmt.setInt(1,tenantId);
stmt.setInt(2,tenantId);
rs=stmt.executeQuery();
rs=stmt.executeQuery();
devices=newArrayList<Device>();
devices=newArrayList<Device>();
while(rs.next()){
while(rs.next()){
@ -175,12 +179,14 @@ public class DeviceDAOImpl implements DeviceDAO {
List<Device>devices=null;
List<Device>devices=null;
try{
try{
conn=this.getConnection();
conn=this.getConnection();
StringselectDBQueryForType="SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME AS DEVICE_NAME, "+
StringselectDBQueryForType="SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, "+
"d.DEVICE_TYPE_ID, d.DEVICE_IDENTIFICATION, d.OWNER, d.TENANT_ID FROM DM_DEVICE d, DM_DEVICE_TYPE t "+
"e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, e.DATE_OF_ENROLMENT FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, d.NAME, "+
"WHERE d.DM_DEVICE.DEVICE_TYPE_ID = t.ID AND t.NAME = ? AND d.TENANT_ID = ?";
"d.DEVICE_IDENTIFICATION, d.OWNER, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, DM_DEVICE_TYPE t "+
"WHERE d.DM_DEVICE.DEVICE_TYPE_ID = t.ID AND t.NAME = ? AND d.TENANT_ID = ?) d1 WHERE d1.DEVICE_ID = e.DEVICE_ID AND TENANT_ID = ?";
stmt=conn.prepareStatement(selectDBQueryForType);
stmt=conn.prepareStatement(selectDBQueryForType);
stmt.setString(1,type);
stmt.setString(1,type);
stmt.setInt(2,tenantId);
stmt.setInt(2,tenantId);
stmt.setInt(3,tenantId);
rs=stmt.executeQuery();
rs=stmt.executeQuery();
devices=newArrayList<Device>();
devices=newArrayList<Device>();
while(rs.next()){
while(rs.next()){
@ -203,11 +209,13 @@ public class DeviceDAOImpl implements DeviceDAO {
try{
try{
conn=this.getConnection();
conn=this.getConnection();
stmt=conn.prepareStatement(
stmt=conn.prepareStatement(
"SELECT t.NAME AS DEVICE_TYPE, d.ID AS DEVICE_ID, d.DESCRIPTION, "+
"SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, d.DEVICE_IDENTIFICATION"+
"d.NAME AS DEVICE_NAME, d.DEVICE_TYPE_ID, d.DEVICE_IDENTIFICATION, d.TENANT_ID FROM "+
" e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, e.DATE_OF_ENROLMENT FROM DM_ENROLMENT e, (SELECT t.NAME AS DEVICE_TYPE, d.ID, d.DESCRIPTION, "+
"DM_DEVICE d, DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.OWNER =? AND d.TENANT_ID = ?");
"d.NAME, d.DEVICE_IDENTIFICATION FROM "+
"DM_DEVICE d, DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.OWNER =? AND d.TENANT_ID = ?) d1 WHERE d1.DEVICE_ID = e.DEVICE_ID AND TENANT_ID = ?");
stmt.setString(1,username);
stmt.setString(1,username);
stmt.setInt(2,tenantId);
stmt.setInt(2,tenantId);
stmt.setInt(3,tenantId);
ResultSetrs=stmt.executeQuery();
ResultSetrs=stmt.executeQuery();
while(rs.next()){
while(rs.next()){
@ -272,12 +280,15 @@ public class DeviceDAOImpl implements DeviceDAO {
try{
try{
conn=this.getConnection();
conn=this.getConnection();
stmt=conn.prepareStatement(
stmt=conn.prepareStatement(
"SELECT d.ID AS DEVICE_ID, d.NAME AS DEVICE_NAME, t.ID AS DEVICE_TYPE_ID, d.DESCRIPTION, "+
"SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, d.DEVICE_IDENTIFICATION "+
"t.NAME AS DEVICE_TYPE, d.DEVICE_TYPE_ID, d.DEVICE_IDENTIFICATION, d.TENANT_ID FROM "+
"e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, e.DATE_OF_ENROLMENT FROM DM_ENROLMENT e, (SELECT d.ID AS DEVICE_ID, d.NAME, d.DESCRIPTION, "+
"t.NAME AS DEVICE_TYPE, d.DEVICE_IDENTIFICATION FROM "+
"DM_DEVICE d, DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID "+
"DM_DEVICE d, DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID "+
"AND d.NAME LIKE ? AND d.TENANT_ID = ?");
"AND d.NAME LIKE ? AND d.TENANT_ID = ?) d1 WHERE d1.DEVICE_ID = e.DEVICE_ID AND TENANT_ID = ?) d1 WHERE d1.DEVICE_ID = e.DEVICE_ID AND TENANT_ID = ?");
stmt.setString(1,deviceName+"%");
stmt.setString(1,deviceName+"%");
stmt.setInt(2,tenantId);
stmt.setInt(2,tenantId);
stmt.setInt(3,tenantId);
stmt.setInt(4,tenantId);
ResultSetrs=stmt.executeQuery();
ResultSetrs=stmt.executeQuery();
while(rs.next()){
while(rs.next()){
@ -420,8 +431,7 @@ public class DeviceDAOImpl implements DeviceDAO {