Search in sources :

Example 56 with Database

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;
}
Also used : DeviceMgtPluginException(org.wso2.iot.sampledevice.plugin.exception.DeviceMgtPluginException) SQLException(java.sql.SQLException) Device(org.wso2.carbon.device.mgt.common.Device) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 57 with Database

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);
    }
}
Also used : DeviceMgtPluginException(org.wso2.iot.sampledevice.plugin.exception.DeviceMgtPluginException) DeviceTypeManagerService(org.wso2.iot.sampledevice.plugin.impl.DeviceTypeManagerService) BundleContext(org.osgi.framework.BundleContext)

Example 58 with Database

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();
    }
}
Also used : ConnectedCupDeviceMgtPluginException(org.coffeeking.connectedcup.plugin.exception.ConnectedCupDeviceMgtPluginException) SQLException(java.sql.SQLException) Device(org.wso2.carbon.device.mgt.common.Device) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement)

Aggregations

SQLException (java.sql.SQLException)29 PreparedStatement (java.sql.PreparedStatement)28 Connection (java.sql.Connection)24 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)23 ResultSet (java.sql.ResultSet)16 ArrayList (java.util.ArrayList)13 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)12 Map (java.util.Map)6 DeviceMgtPluginException (org.wso2.iot.sampledevice.plugin.exception.DeviceMgtPluginException)6 HashMap (java.util.HashMap)5 BpelDatabase (org.apache.ode.bpel.engine.BpelDatabase)5 File (java.io.File)4 InstanceFilter (org.apache.ode.bpel.common.InstanceFilter)4 BpelDAOConnection (org.apache.ode.bpel.dao.BpelDAOConnection)4 InstanceManagementException (org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.InstanceManagementException)4 Device (org.wso2.carbon.device.mgt.common.Device)4 IOException (java.io.IOException)3 Collection (java.util.Collection)3 DataSource (javax.sql.DataSource)3 ProcessInstanceDAO (org.apache.ode.bpel.dao.ProcessInstanceDAO)3