|
|
@ -32,143 +32,179 @@ import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
public class DeviceTypeDAOImpl implements DeviceTypeDAO {
|
|
|
|
public class DeviceTypeDAOImpl implements DeviceTypeDAO {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void addDeviceType(DeviceType deviceType) throws DeviceManagementDAOException {
|
|
|
|
public void addDeviceType(DeviceType deviceType, int providerTenantId, boolean isSharedWithAllTenants)
|
|
|
|
Connection conn;
|
|
|
|
throws DeviceManagementDAOException {
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
Connection conn;
|
|
|
|
try {
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
conn = this.getConnection();
|
|
|
|
try {
|
|
|
|
stmt = conn.prepareStatement("INSERT INTO DM_DEVICE_TYPE (NAME) VALUES (?)");
|
|
|
|
conn = this.getConnection();
|
|
|
|
stmt.setString(1, deviceType.getName());
|
|
|
|
stmt = conn.prepareStatement(
|
|
|
|
stmt.execute();
|
|
|
|
"INSERT INTO DM_DEVICE_TYPE (NAME,PROVIDER_TENANT_ID,SHARED_WITH_ALL_TENANTS) VALUES (?,?,?)");
|
|
|
|
} catch (SQLException e) {
|
|
|
|
stmt.setString(1, deviceType.getName());
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while registering the device type " +
|
|
|
|
stmt.setInt(2, providerTenantId);
|
|
|
|
"'" + deviceType.getName() + "'", e);
|
|
|
|
stmt.setBoolean(3, isSharedWithAllTenants);
|
|
|
|
} finally {
|
|
|
|
stmt.execute();
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
} catch (SQLException e) {
|
|
|
|
}
|
|
|
|
throw new DeviceManagementDAOException(
|
|
|
|
}
|
|
|
|
"Error occurred while registering the device type '" + deviceType.getName() + "'", e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
@Override
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
public void updateDeviceType(DeviceType deviceType) throws DeviceManagementDAOException {
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void updateDeviceType(DeviceType deviceType, int tenantId)
|
|
|
|
public List<DeviceType> getDeviceTypes() throws DeviceManagementDAOException {
|
|
|
|
throws DeviceManagementDAOException {
|
|
|
|
Connection conn;
|
|
|
|
}
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
|
|
|
ResultSet rs = null;
|
|
|
|
@Override
|
|
|
|
List<DeviceType> deviceTypes = new ArrayList<>();
|
|
|
|
public List<DeviceType> getDeviceTypes(int tenantId) throws DeviceManagementDAOException {
|
|
|
|
try {
|
|
|
|
Connection conn;
|
|
|
|
conn = this.getConnection();
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
String sql = "SELECT ID AS DEVICE_TYPE_ID, NAME AS DEVICE_TYPE FROM DM_DEVICE_TYPE";
|
|
|
|
ResultSet rs = null;
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
List<DeviceType> deviceTypes = new ArrayList<>();
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
try {
|
|
|
|
|
|
|
|
conn = this.getConnection();
|
|
|
|
while (rs.next()) {
|
|
|
|
String sql =
|
|
|
|
DeviceType deviceType = new DeviceType();
|
|
|
|
"SELECT ID AS DEVICE_TYPE_ID, NAME AS DEVICE_TYPE FROM DM_DEVICE_TYPE where PROVIDER_TENANT_ID =" +
|
|
|
|
deviceType.setId(rs.getInt("DEVICE_TYPE_ID"));
|
|
|
|
"? OR SHARED_WITH_ALL_TENANTS = TRUE";
|
|
|
|
deviceType.setName(rs.getString("DEVICE_TYPE"));
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
deviceTypes.add(deviceType);
|
|
|
|
stmt.setInt(1, tenantId);
|
|
|
|
}
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
return deviceTypes;
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
while (rs.next()) {
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while fetching the registered device types", e);
|
|
|
|
DeviceType deviceType = new DeviceType();
|
|
|
|
} finally {
|
|
|
|
deviceType.setId(rs.getInt("DEVICE_TYPE_ID"));
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
deviceType.setName(rs.getString("DEVICE_TYPE"));
|
|
|
|
}
|
|
|
|
deviceTypes.add(deviceType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return deviceTypes;
|
|
|
|
@Override
|
|
|
|
} catch (SQLException e) {
|
|
|
|
public List<DeviceType> getDeviceTypes(int tenantId) throws DeviceManagementDAOException {
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while fetching the registered device types", e);
|
|
|
|
Connection conn;
|
|
|
|
} finally {
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
ResultSet rs = null;
|
|
|
|
}
|
|
|
|
List<DeviceType> deviceTypes = new ArrayList<>();
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
|
|
|
|
conn = this.getConnection();
|
|
|
|
@Override
|
|
|
|
String sql =
|
|
|
|
public List<DeviceType> getDeviceTypesByProvider(int tenantId) throws DeviceManagementDAOException {
|
|
|
|
"SELECT ID AS DEVICE_TYPE_ID, NAME AS DEVICE_TYPE FROM DM_DEVICE_TYPE where PROVIDER_TENANT_ID =" +
|
|
|
|
Connection conn;
|
|
|
|
"? OR SHARED_WITH_ALL_TENANTS = TRUE";
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
ResultSet rs = null;
|
|
|
|
stmt.setInt(1, tenantId);
|
|
|
|
List<DeviceType> deviceTypes = new ArrayList<>();
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
try {
|
|
|
|
|
|
|
|
conn = this.getConnection();
|
|
|
|
while (rs.next()) {
|
|
|
|
String sql =
|
|
|
|
DeviceType deviceType = new DeviceType();
|
|
|
|
"SELECT ID AS DEVICE_TYPE_ID, NAME AS DEVICE_TYPE FROM DM_DEVICE_TYPE where PROVIDER_TENANT_ID =?";
|
|
|
|
deviceType.setId(rs.getInt("DEVICE_TYPE_ID"));
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
deviceType.setName(rs.getString("DEVICE_TYPE"));
|
|
|
|
stmt.setInt(1, tenantId);
|
|
|
|
deviceTypes.add(deviceType);
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
}
|
|
|
|
|
|
|
|
return deviceTypes;
|
|
|
|
while (rs.next()) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
DeviceType deviceType = new DeviceType();
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while fetching the registered device types", e);
|
|
|
|
deviceType.setId(rs.getInt("DEVICE_TYPE_ID"));
|
|
|
|
} finally {
|
|
|
|
deviceType.setName(rs.getString("DEVICE_TYPE"));
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
deviceTypes.add(deviceType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return deviceTypes;
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
@Override
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while fetching the registered device types", e);
|
|
|
|
public DeviceType getDeviceType(int id) throws DeviceManagementDAOException {
|
|
|
|
} finally {
|
|
|
|
Connection conn;
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
}
|
|
|
|
ResultSet rs = null;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
|
|
|
|
conn = this.getConnection();
|
|
|
|
@Override
|
|
|
|
String sql = "SELECT ID AS DEVICE_TYPE_ID, NAME AS DEVICE_TYPE FROM DM_DEVICE_TYPE WHERE ID = ?";
|
|
|
|
public List<DeviceType> getSharedDeviceTypes() throws DeviceManagementDAOException {
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
Connection conn;
|
|
|
|
stmt.setInt(1, id);
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
|
|
|
ResultSet rs = null;
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
List<DeviceType> deviceTypes = new ArrayList<>();
|
|
|
|
DeviceType deviceType = null;
|
|
|
|
try {
|
|
|
|
while (rs.next()) {
|
|
|
|
conn = this.getConnection();
|
|
|
|
deviceType = new DeviceType();
|
|
|
|
String sql =
|
|
|
|
deviceType.setId(rs.getInt("DEVICE_TYPE_ID"));
|
|
|
|
"SELECT ID AS DEVICE_TYPE_ID, NAME AS DEVICE_TYPE FROM DM_DEVICE_TYPE where " +
|
|
|
|
deviceType.setName(rs.getString("DEVICE_TYPE"));
|
|
|
|
"SHARED_WITH_ALL_TENANTS = TRUE";
|
|
|
|
}
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
return deviceType;
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while fetching the registered device type", e);
|
|
|
|
while (rs.next()) {
|
|
|
|
} finally {
|
|
|
|
DeviceType deviceType = new DeviceType();
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
deviceType.setId(rs.getInt("DEVICE_TYPE_ID"));
|
|
|
|
}
|
|
|
|
deviceType.setName(rs.getString("DEVICE_TYPE"));
|
|
|
|
}
|
|
|
|
deviceTypes.add(deviceType);
|
|
|
|
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
return deviceTypes;
|
|
|
|
public DeviceType getDeviceType(String type) throws DeviceManagementDAOException {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
Connection conn;
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while fetching the registered device types", e);
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
} finally {
|
|
|
|
ResultSet rs = null;
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
DeviceType deviceType = null;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
}
|
|
|
|
conn = this.getConnection();
|
|
|
|
|
|
|
|
String sql = "SELECT ID From DM_DEVICE_TYPE WHERE NAME = ?";
|
|
|
|
@Override
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
public DeviceType getDeviceType(int id) throws DeviceManagementDAOException {
|
|
|
|
stmt.setString(1, type);
|
|
|
|
Connection conn;
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
|
|
|
ResultSet rs = null;
|
|
|
|
if (rs.next()) {
|
|
|
|
try {
|
|
|
|
deviceType = new DeviceType();
|
|
|
|
conn = this.getConnection();
|
|
|
|
deviceType.setId(rs.getInt("ID"));
|
|
|
|
String sql = "SELECT ID AS DEVICE_TYPE_ID, NAME AS DEVICE_TYPE FROM DM_DEVICE_TYPE WHERE ID = ?";
|
|
|
|
deviceType.setName(type);
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
}
|
|
|
|
stmt.setInt(1, id);
|
|
|
|
return deviceType;
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
} catch (SQLException e) {
|
|
|
|
DeviceType deviceType = null;
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while fetch device type id for device type " +
|
|
|
|
while (rs.next()) {
|
|
|
|
"'" + type + "'", e);
|
|
|
|
deviceType = new DeviceType();
|
|
|
|
} finally {
|
|
|
|
deviceType.setId(rs.getInt("DEVICE_TYPE_ID"));
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
deviceType.setName(rs.getString("DEVICE_TYPE"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return deviceType;
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
@Override
|
|
|
|
throw new DeviceManagementDAOException(
|
|
|
|
public void removeDeviceType(String type) throws DeviceManagementDAOException {
|
|
|
|
"Error occurred while fetching the registered device type", e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
}
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
|
|
|
|
}
|
|
|
|
private Connection getConnection() throws SQLException {
|
|
|
|
}
|
|
|
|
return DeviceManagementDAOFactory.getConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public DeviceType getDeviceType(String type, int tenantId) throws
|
|
|
|
|
|
|
|
DeviceManagementDAOException {
|
|
|
|
|
|
|
|
Connection conn;
|
|
|
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
|
|
|
ResultSet rs = null;
|
|
|
|
|
|
|
|
DeviceType deviceType = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
conn = this.getConnection();
|
|
|
|
|
|
|
|
String sql = "SELECT ID AS DEVICE_TYPE_ID FROM DM_DEVICE_TYPE WHERE (PROVIDER_TENANT_ID =? OR " +
|
|
|
|
|
|
|
|
"SHARED_WITH_ALL_TENANTS = TRUE) AND NAME =?";
|
|
|
|
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
|
|
|
|
stmt.setInt(1, tenantId);
|
|
|
|
|
|
|
|
stmt.setString(2, type);
|
|
|
|
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
|
|
|
|
if (rs.next()) {
|
|
|
|
|
|
|
|
deviceType = new DeviceType();
|
|
|
|
|
|
|
|
deviceType.setId(rs.getInt("DEVICE_TYPE_ID"));
|
|
|
|
|
|
|
|
deviceType.setName(type);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return deviceType;
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
|
|
|
throw new DeviceManagementDAOException(
|
|
|
|
|
|
|
|
"Error occurred while fetch device type id for device type '" + type + "'", e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void removeDeviceType(String type, int tenantId) throws DeviceManagementDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Connection getConnection() throws SQLException {
|
|
|
|
|
|
|
|
return DeviceManagementDAOFactory.getConnection();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|