use of org.wso2.carbon.humantask.core.db.Database in project product-iots by wso2.
the class DeviceTypeDAOImpl method getDevice.
public Device getDevice(String deviceId) throws DeviceMgtPluginException {
Connection conn = null;
PreparedStatement stmt = null;
Device iotDevice = null;
ResultSet resultSet = null;
try {
conn = DeviceTypeDAO.getConnection();
String selectDBQuery = "SELECT sampledevice_DEVICE_ID, DEVICE_NAME" + " FROM sampledevice_DEVICE WHERE sampledevice_DEVICE_ID = ?";
stmt = conn.prepareStatement(selectDBQuery);
stmt.setString(1, deviceId);
resultSet = stmt.executeQuery();
if (resultSet.next()) {
iotDevice = new Device();
iotDevice.setName(resultSet.getString(DeviceTypeConstants.DEVICE_PLUGIN_DEVICE_NAME));
if (log.isDebugEnabled()) {
log.debug("sampledevice device " + deviceId + " data has been fetched from " + "sampledevice database.");
}
}
} catch (SQLException e) {
String msg = "Error occurred while fetching sampledevice device : '" + deviceId + "'";
log.error(msg, e);
throw new DeviceMgtPluginException(msg, e);
} finally {
DeviceTypeUtils.cleanupResources(stmt, resultSet);
DeviceTypeDAO.closeConnection();
}
return iotDevice;
}
use of org.wso2.carbon.humantask.core.db.Database in project product-iots by wso2.
the class ServiceComponent method activate.
protected void activate(ComponentContext ctx) {
if (log.isDebugEnabled()) {
log.debug("Activating b Management Service Component");
}
try {
DeviceTypeManagerService deviceTypeManagerService = new DeviceTypeManagerService();
BundleContext bundleContext = ctx.getBundleContext();
serviceRegistration = bundleContext.registerService(DeviceManagementService.class.getName(), deviceTypeManagerService, null);
String setupOption = System.getProperty("setup");
if (setupOption != null) {
if (log.isDebugEnabled()) {
log.debug("-Dsetup is enabled. Iot Device management repository schema " + "initialization is about to begin");
}
try {
DeviceTypeUtils.setupDeviceManagementSchema();
} catch (DeviceMgtPluginException e) {
log.error("Exception occurred while initializing device management database " + "schema", e);
}
}
if (log.isDebugEnabled()) {
log.debug("b Management Service Component has been successfully activated");
}
} catch (Throwable e) {
log.error("Error occurred while activating Current Sensor Management Service " + "Component", e);
}
}
use of org.wso2.carbon.humantask.core.db.Database in project product-iots by wso2.
the class ConnectedCupDAO method getAllDevices.
public List<Device> getAllDevices() throws ConnectedCupDeviceMgtPluginException {
Connection conn = null;
PreparedStatement stmt = null;
ResultSet resultSet = null;
Device connectedCupDevice;
List<Device> iotDevices = new ArrayList<>();
try {
conn = ConnectedCupDAOUtil.getConnection();
String selectDBQuery = "SELECT CONNECTED_CUP_DEVICE_ID, DEVICE_NAME" + "FROM CONNECTED_CUP_DEVICE";
stmt = conn.prepareStatement(selectDBQuery);
resultSet = stmt.executeQuery();
while (resultSet.next()) {
connectedCupDevice = new Device();
connectedCupDevice.setDeviceIdentifier(resultSet.getString(ConnectedCupConstants.DEVICE_PLUGIN_DEVICE_ID));
connectedCupDevice.setName(resultSet.getString(ConnectedCupConstants.DEVICE_PLUGIN_DEVICE_NAME));
}
if (log.isDebugEnabled()) {
log.debug("All Connected Cup device details have fetched from Connected Cup database" + ".");
}
return iotDevices;
} catch (SQLException e) {
String msg = "Error occurred while fetching all Connected Cup device data'";
log.error(msg, e);
throw new ConnectedCupDeviceMgtPluginException(msg, e);
} finally {
ConnectedCupUtils.cleanupResources(stmt, resultSet);
ConnectedCupDAOUtil.closeConnection();
}
}
Aggregations