Search in sources :

Example 11 with DeviceMgtPluginException

use of org.wso2.iot.sampledevice.plugin.exception.DeviceMgtPluginException in project product-iots by wso2.

the class DeviceTypeManager method disenrollDevice.

@Override
public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
    boolean status;
    try {
        if (log.isDebugEnabled()) {
            log.debug("Dis-enrolling sampledevice device : " + deviceId);
        }
        DeviceTypeDAO.beginTransaction();
        status = deviceTypeDAO.getDeviceTypeDAO().deleteDevice(deviceId.getId());
        DeviceTypeDAO.commitTransaction();
    } catch (DeviceMgtPluginException e) {
        try {
            DeviceTypeDAO.rollbackTransaction();
        } catch (DeviceMgtPluginException iotDAOEx) {
            String msg = "Error occurred while roll back the device dis enrol transaction :" + deviceId.toString();
            log.warn(msg, iotDAOEx);
        }
        String msg = "Error while removing the sampledevice device : " + deviceId.getId();
        log.error(msg, e);
        throw new DeviceManagementException(msg, e);
    }
    return status;
}
Also used : DeviceMgtPluginException(org.wso2.iot.sampledevice.plugin.exception.DeviceMgtPluginException) DeviceManagementException(org.wso2.carbon.device.mgt.common.DeviceManagementException)

Example 12 with DeviceMgtPluginException

use of org.wso2.iot.sampledevice.plugin.exception.DeviceMgtPluginException in project product-iots by wso2.

the class DeviceTypeDAO method beginTransaction.

public static void beginTransaction() throws DeviceMgtPluginException {
    try {
        Connection conn = dataSource.getConnection();
        conn.setAutoCommit(false);
        currentConnection.set(conn);
    } catch (SQLException e) {
        throw new DeviceMgtPluginException("Error occurred while retrieving datasource connection", e);
    }
}
Also used : DeviceMgtPluginException(org.wso2.iot.sampledevice.plugin.exception.DeviceMgtPluginException) SQLException(java.sql.SQLException) Connection(java.sql.Connection)

Aggregations

DeviceMgtPluginException (org.wso2.iot.sampledevice.plugin.exception.DeviceMgtPluginException)12 SQLException (java.sql.SQLException)7 Connection (java.sql.Connection)6 PreparedStatement (java.sql.PreparedStatement)5 DeviceManagementException (org.wso2.carbon.device.mgt.common.DeviceManagementException)4 ResultSet (java.sql.ResultSet)2 Device (org.wso2.carbon.device.mgt.common.Device)2 ArrayList (java.util.ArrayList)1 Context (javax.naming.Context)1 InitialContext (javax.naming.InitialContext)1 NamingException (javax.naming.NamingException)1 DataSource (javax.sql.DataSource)1 BundleContext (org.osgi.framework.BundleContext)1 DeviceTypeManagerService (org.wso2.iot.sampledevice.plugin.impl.DeviceTypeManagerService)1