use of org.coffeeking.connectedcup.plugin.exception.ConnectedCupDeviceMgtPluginException in project product-iots by wso2.
the class ConnectedCupDAO method addDevice.
public boolean addDevice(Device connectedCupDevice) throws ConnectedCupDeviceMgtPluginException {
boolean status = false;
Connection conn = null;
PreparedStatement stmt = null;
try {
conn = ConnectedCupDAOUtil.getConnection();
String createDBQuery = "INSERT INTO CONNECTED_CUP_DEVICE(CONNECTED_CUP_DEVICE_ID, DEVICE_NAME ) VALUES (?, ?)";
stmt = conn.prepareStatement(createDBQuery);
stmt.setString(1, connectedCupDevice.getDeviceIdentifier());
stmt.setString(2, connectedCupDevice.getName());
int rows = stmt.executeUpdate();
if (rows > 0) {
status = true;
if (log.isDebugEnabled()) {
log.debug("Connected Cup device " + connectedCupDevice.getDeviceIdentifier() + " data has been added to the Connected Cup database.");
}
}
} catch (SQLException e) {
String msg = "Error occurred while adding the Connected Cup device '" + connectedCupDevice.getDeviceIdentifier() + "' to the Connected Cup db.";
log.error(msg, e);
throw new ConnectedCupDeviceMgtPluginException(msg, e);
} finally {
ConnectedCupUtils.cleanupResources(stmt, null);
}
return status;
}
use of org.coffeeking.connectedcup.plugin.exception.ConnectedCupDeviceMgtPluginException in project product-iots by wso2.
the class ConnectedCupDAO method getDevice.
public Device getDevice(String deviceId) throws ConnectedCupDeviceMgtPluginException {
Connection conn = null;
PreparedStatement stmt = null;
Device connectedCupDevice = null;
ResultSet resultSet = null;
try {
conn = ConnectedCupDAOUtil.getConnection();
String selectDBQuery = "SELECT CONNECTED_CUP_DEVICE_ID, DEVICE_NAME FROM CONNECTED_CUP_DEVICE WHERE CONNECTED_CUP_DEVICE_ID = ?";
stmt = conn.prepareStatement(selectDBQuery);
stmt.setString(1, deviceId);
resultSet = stmt.executeQuery();
if (resultSet.next()) {
connectedCupDevice = new Device();
connectedCupDevice.setName(resultSet.getString(ConnectedCupConstants.DEVICE_PLUGIN_DEVICE_NAME));
if (log.isDebugEnabled()) {
log.debug("Connected Cup service " + deviceId + " data has been fetched from" + "Connected Cup database.");
}
}
} catch (SQLException e) {
String msg = "Error occurred while fetching Connected Cup device : '" + deviceId + "'";
log.error(msg, e);
throw new ConnectedCupDeviceMgtPluginException(msg, e);
} finally {
ConnectedCupUtils.cleanupResources(stmt, resultSet);
ConnectedCupDAOUtil.closeConnection();
}
return connectedCupDevice;
}
use of org.coffeeking.connectedcup.plugin.exception.ConnectedCupDeviceMgtPluginException in project product-iots by wso2.
the class ConnectedCupManager method modifyEnrollment.
@Override
public boolean modifyEnrollment(Device device) throws DeviceManagementException {
boolean status;
try {
if (log.isDebugEnabled()) {
log.debug("Modifying the Connected Cup device enrollment data");
}
ConnectedCupDAOUtil.beginTransaction();
status = CONNECTED_CUP_DAO_UTIL.getConnectedCupDeviceDAO().updateDevice(device);
ConnectedCupDAOUtil.commitTransaction();
} catch (ConnectedCupDeviceMgtPluginException e) {
try {
ConnectedCupDAOUtil.rollbackTransaction();
} catch (ConnectedCupDeviceMgtPluginException iotDAOEx) {
String msg = "Error occurred while roll back the update device transaction :" + device.toString();
log.warn(msg, iotDAOEx);
}
String msg = "Error while updating the enrollment of the Connected Cup device : " + device.getDeviceIdentifier();
log.error(msg, e);
throw new DeviceManagementException(msg, e);
}
return status;
}
use of org.coffeeking.connectedcup.plugin.exception.ConnectedCupDeviceMgtPluginException in project product-iots by wso2.
the class ConnectedCupManager method disenrollDevice.
@Override
public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
boolean status;
try {
if (log.isDebugEnabled()) {
log.debug("Dis-enrolling Connected Cup device : " + deviceId);
}
ConnectedCupDAOUtil.beginTransaction();
status = CONNECTED_CUP_DAO_UTIL.getConnectedCupDeviceDAO().deleteDevice(deviceId.getId());
ConnectedCupDAOUtil.commitTransaction();
} catch (ConnectedCupDeviceMgtPluginException e) {
try {
ConnectedCupDAOUtil.rollbackTransaction();
} catch (ConnectedCupDeviceMgtPluginException 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 Connected Cup device : " + deviceId.getId();
log.error(msg, e);
throw new DeviceManagementException(msg, e);
}
return status;
}
use of org.coffeeking.connectedcup.plugin.exception.ConnectedCupDeviceMgtPluginException in project product-iots by wso2.
the class ConnectedCupDAOUtil method beginTransaction.
public static void beginTransaction() throws ConnectedCupDeviceMgtPluginException {
try {
Connection conn = dataSource.getConnection();
conn.setAutoCommit(false);
currentConnection.set(conn);
} catch (SQLException e) {
throw new ConnectedCupDeviceMgtPluginException("Error occurred while retrieving datasource connection", e);
}
}
Aggregations