forked from community/device-mgt-core
parent
1c2ede6be5
commit
f2c6eab6a3
@ -0,0 +1,63 @@
|
||||
package org.wso2.carbon.device.mgt.mobile.dao;
|
||||
|
||||
import org.wso2.carbon.device.mgt.mobile.dto.DeviceOperation;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class represents the mapping between device and operations.
|
||||
*/
|
||||
public interface DeviceOperationDAO {
|
||||
/**
|
||||
* Add a new mapping to plugin device_operation table.
|
||||
*
|
||||
* @param deviceOperation DeviceOperation object that holds data related to the DeviceOperation
|
||||
* to be inserted.
|
||||
* @return The status of the operation. If the insert was successful or not.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
boolean addDeviceOperation(DeviceOperation deviceOperation)
|
||||
throws MobileDeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Update a feature in the feature table.
|
||||
*
|
||||
* @param deviceOperation DeviceOperation object that holds data has to be updated.
|
||||
* @return The status of the operation. If the update was successful or not.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
boolean updateDeviceOperation(DeviceOperation deviceOperation)
|
||||
throws MobileDeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Delete a given device operation from device operation table.
|
||||
*
|
||||
* @param deviceId Device id of the mapping to be deleted.
|
||||
* @param operationId Operation id of the mapping to be deleted.
|
||||
* @return The status of the operation. If the deletion was successful or not.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
boolean deleteDeviceOperation(String deviceId, int operationId)
|
||||
throws MobileDeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Retrieve a given device operation from plugin database.
|
||||
*
|
||||
* @param deviceId Device id of the mapping to be retrieved.
|
||||
* @param operationId Operation id of the mapping to be retrieved.
|
||||
* @return DeviceOperation object that holds data of the device operation mapping represented by
|
||||
* deviceId and operationId.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
DeviceOperation getDeviceOperation(String deviceId, int operationId)
|
||||
throws MobileDeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Retrieve all the device operation mapping from plugin database.
|
||||
*
|
||||
* @return Device operation mapping object list.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
List<DeviceOperation> getAllDeviceOperationOfDevice(String deviceId)
|
||||
throws MobileDeviceManagementDAOException;
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package org.wso2.carbon.device.mgt.mobile.dao;
|
||||
|
||||
import org.wso2.carbon.device.mgt.mobile.dto.Operation;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class represents the key operations associated with persisting operation related
|
||||
* information.
|
||||
*/
|
||||
public interface OperationDAO {
|
||||
|
||||
/**
|
||||
* Add a new operation to plugin operation table.
|
||||
* @param operation Operation object that holds data related to the operation to be inserted.
|
||||
* @return The status of the operation. If the insert was successful or not.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
boolean addOperation(Operation operation) throws MobileDeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Update a operation in the operation table.
|
||||
* @param operation Operation object that holds data has to be updated.
|
||||
* @return The status of the operation. If the update was successful or not.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
boolean updateOperation(Operation operation) throws MobileDeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Delete a given operation from plugin database.
|
||||
* @param operationId Operation code of the operation to be deleted.
|
||||
* @return The status of the operation. If the operationId was successful or not.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
boolean deleteOperation(int operationId) throws MobileDeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Retrieve a given operation from plugin database.
|
||||
* @param operationId Operation id of the operation to be retrieved.
|
||||
* @return Operation object that holds data of the feature represented by operationId.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
Operation getOperation(int operationId) throws MobileDeviceManagementDAOException;
|
||||
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
package org.wso2.carbon.device.mgt.mobile.dao;
|
||||
|
||||
import org.wso2.carbon.device.mgt.mobile.dto.OperationProperty;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class represents the key operations associated with persisting operation property related
|
||||
* information.
|
||||
*/
|
||||
public interface OperationPropertyDAO {
|
||||
/**
|
||||
* Add a new mapping to plugin operation property table.
|
||||
*
|
||||
* @param operationProperty OperationProperty object that holds data related to the operation property to be inserted.
|
||||
* @return The status of the operation. If the insert was successful or not.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
boolean addOperationProperty(OperationProperty operationProperty)
|
||||
throws MobileDeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Update a feature in the feature table.
|
||||
*
|
||||
* @param operationProperty DeviceOperation object that holds data has to be updated.
|
||||
* @return The status of the operation. If the update was successful or not.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
boolean updateOperationProperty(OperationProperty operationProperty)
|
||||
throws MobileDeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Delete a given device operation from plugin database.
|
||||
*
|
||||
* @param operationPropertyId Device id of the mapping to be deleted.
|
||||
* @return The status of the operation. If the deletion was successful or not.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
boolean deleteOperationProperty(int operationPropertyId)
|
||||
throws MobileDeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Retrieve a given device operation from plugin database.
|
||||
*
|
||||
* @param deviceId Device id of the mapping to be retrieved.
|
||||
* @param operationId Operation id of the mapping to be retrieved.
|
||||
* @return DeviceOperation object that holds data of the device operation mapping represented by deviceId and operationId.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
OperationProperty getOperationProperty(String deviceId, int operationId)
|
||||
throws MobileDeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* Retrieve all the device operation mapping from plugin database.
|
||||
*
|
||||
* @return Device operation mapping object list.
|
||||
* @throws MobileDeviceManagementDAOException
|
||||
*/
|
||||
List<OperationProperty> getAllDeviceOperationOfDevice(String deviceId)
|
||||
throws MobileDeviceManagementDAOException;
|
||||
}
|
@ -0,0 +1,196 @@
|
||||
package org.wso2.carbon.device.mgt.mobile.dao.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.DeviceOperationDAO;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil;
|
||||
import org.wso2.carbon.device.mgt.mobile.dto.DeviceOperation;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Implementation of DeviceOperationDAO
|
||||
*/
|
||||
public class DeviceOperationDAOImpl implements DeviceOperationDAO {
|
||||
|
||||
private DataSource dataSource;
|
||||
private static final Log log = LogFactory.getLog(DeviceOperationDAOImpl.class);
|
||||
|
||||
public DeviceOperationDAOImpl(DataSource dataSource) {
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addDeviceOperation(DeviceOperation deviceOperation)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
boolean status = false;
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String createDBQuery =
|
||||
"INSERT INTO MBL_DEVICE_OPERATION(DEVICE_ID, OPERATION_ID, SENT_DATE, RECEIVED_DATE) VALUES (?, ?, ?, ?)";
|
||||
|
||||
stmt = conn.prepareStatement(createDBQuery);
|
||||
stmt.setString(1, deviceOperation.getDeviceId());
|
||||
stmt.setInt(2, deviceOperation.getOperationId());
|
||||
stmt.setInt(3, deviceOperation.getSentDate());
|
||||
stmt.setInt(4, deviceOperation.getReceivedDate());
|
||||
int rows = stmt.executeUpdate();
|
||||
if (rows > 0) {
|
||||
status = true;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while adding device id - '" +
|
||||
deviceOperation.getDeviceId() + " and operation id - " + deviceOperation.getOperationId() + "of mapping table MBL_DEVICE_OPERATION";;
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateDeviceOperation(DeviceOperation deviceOperation)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
boolean status = false;
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String updateDBQuery =
|
||||
"UPDATE MBL_DEVICE_OPERATION SET SENT_DATE = ?, RECEIVED_DATE = ? WHERE DEVICE_ID = ? and OPERATION_ID=?";
|
||||
stmt = conn.prepareStatement(updateDBQuery);
|
||||
stmt.setInt(1, deviceOperation.getSentDate());
|
||||
stmt.setInt(2, deviceOperation.getReceivedDate());
|
||||
stmt.setString(3, deviceOperation.getDeviceId());
|
||||
stmt.setInt(4, deviceOperation.getOperationId());
|
||||
int rows = stmt.executeUpdate();
|
||||
if (rows > 0) {
|
||||
status = true;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while updating device id - '" +
|
||||
deviceOperation.getDeviceId() + " and operation id - " + deviceOperation.getOperationId() + "of mapping table MBL_DEVICE_OPERATION";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteDeviceOperation(String deviceId, int operationId)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
boolean status = false;
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String deleteDBQuery =
|
||||
"DELETE FROM MBL_DEVICE_OPERATION WHERE DEVICE_ID = ? and OPERATION_ID=?";
|
||||
stmt = conn.prepareStatement(deleteDBQuery);
|
||||
stmt.setString(1, deviceId);
|
||||
stmt.setInt(2, operationId);
|
||||
int rows = stmt.executeUpdate();
|
||||
if(rows>0){
|
||||
status = true;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while deleting mapping table MBL_DEVICE_OPERATION with device id - '" +
|
||||
deviceId + " and operation id - " + operationId;
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeviceOperation getDeviceOperation(String deviceId, int operationId)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
DeviceOperation deviceOperation = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String selectDBQuery =
|
||||
"SELECT DEVICE_ID, OPERATION_ID, SENT_DATE, RECEIVED_DATE FROM MBL_DEVICE_OPERATION WHERE DEVICE_ID = ? and OPERATION_ID=?";
|
||||
stmt = conn.prepareStatement(selectDBQuery);
|
||||
stmt.setString(1, deviceId);
|
||||
stmt.setInt(2, operationId);
|
||||
ResultSet resultSet = stmt.executeQuery();
|
||||
while (resultSet.next()) {
|
||||
deviceOperation = new DeviceOperation();
|
||||
deviceOperation.setDeviceId(resultSet.getString(1));
|
||||
deviceOperation.setOperationId(resultSet.getInt(2));
|
||||
deviceOperation.setSentDate(resultSet.getInt(3));
|
||||
deviceOperation.setReceivedDate(resultSet.getInt(4));
|
||||
break;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while fetching mapping table MBL_DEVICE_OPERATION entry with device id - '" +
|
||||
deviceId + " and operation id - " + operationId;
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
return deviceOperation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeviceOperation> getAllDeviceOperationOfDevice(String deviceId)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
DeviceOperation deviceOperation = null;
|
||||
List<DeviceOperation> deviceOperations=new ArrayList<DeviceOperation>();
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String selectDBQuery =
|
||||
"SELECT DEVICE_ID, OPERATION_ID, SENT_DATE, RECEIVED_DATE FROM MBL_DEVICE_OPERATION WHERE DEVICE_ID = ?";
|
||||
stmt = conn.prepareStatement(selectDBQuery);
|
||||
stmt.setString(1, deviceId);
|
||||
ResultSet resultSet = stmt.executeQuery();
|
||||
while (resultSet.next()) {
|
||||
deviceOperation = new DeviceOperation();
|
||||
deviceOperation.setDeviceId(resultSet.getString(1));
|
||||
deviceOperation.setOperationId(resultSet.getInt(2));
|
||||
deviceOperation.setSentDate(resultSet.getInt(3));
|
||||
deviceOperation.setReceivedDate(resultSet.getInt(4));
|
||||
deviceOperations.add(deviceOperation);
|
||||
break;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while fetching mapping table MBL_DEVICE_OPERATION entry with device id - '" +
|
||||
deviceId;
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
return deviceOperations;
|
||||
}
|
||||
|
||||
private Connection getConnection() throws MobileDeviceManagementDAOException {
|
||||
try {
|
||||
return dataSource.getConnection();
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while obtaining a connection from the mobile device " +
|
||||
"management metadata repository datasource.";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,186 @@
|
||||
package org.wso2.carbon.device.mgt.mobile.dao.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.FeaturePropertyDAO;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil;
|
||||
import org.wso2.carbon.device.mgt.mobile.dto.FeatureProperty;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Implementation of FeaturePropertyDAO
|
||||
*/
|
||||
public class FeaturePropertyDAOImpl implements FeaturePropertyDAO {
|
||||
|
||||
private DataSource dataSource;
|
||||
private static final Log log = LogFactory.getLog(FeaturePropertyDAOImpl.class);
|
||||
|
||||
public FeaturePropertyDAOImpl(DataSource dataSource) {
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addFeatureProperty(FeatureProperty featureProperty)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
boolean status = false;
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String createDBQuery =
|
||||
"INSERT INTO MBL_FEATURE_PROPERTY(PROPERTY, FEATURE_ID) VALUES (?, ?)";
|
||||
|
||||
stmt = conn.prepareStatement(createDBQuery);
|
||||
stmt.setString(1, featureProperty.getProperty());
|
||||
stmt.setString(2, featureProperty.getFeatureID());
|
||||
int rows = stmt.executeUpdate();
|
||||
if (rows > 0) {
|
||||
status = true;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while adding property id - '" +
|
||||
featureProperty.getFeatureID() + "'";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateFeatureProperty(FeatureProperty featureProperty)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
boolean status = false;
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String updateDBQuery =
|
||||
"UPDATE MBL_FEATURE_PROPERTY SET PROPERTY = ?, FEATURE_ID = ? WHERE PROPERTY_ID = ?";
|
||||
stmt = conn.prepareStatement(updateDBQuery);
|
||||
stmt.setString(1, featureProperty.getProperty());
|
||||
stmt.setString(2, featureProperty.getFeatureID());
|
||||
stmt.setInt(3, featureProperty.getPropertyId());
|
||||
int rows = stmt.executeUpdate();
|
||||
if (rows > 0) {
|
||||
status = true;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while updating the feature property with property id - '" +
|
||||
featureProperty.getPropertyId() + "'";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteFeatureProperty(int propertyId)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
boolean status = false;
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String deleteDBQuery =
|
||||
"DELETE FROM MBL_FEATURE_PROPERTY WHERE PROPERTY_ID = ?";
|
||||
stmt = conn.prepareStatement(deleteDBQuery);
|
||||
stmt.setInt(1, propertyId);
|
||||
int rows = stmt.executeUpdate();
|
||||
if (rows > 0) {
|
||||
status = true;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while deleting feature property with property Id - " +
|
||||
propertyId;
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureProperty getFeatureProperty(int propertyId)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
FeatureProperty featureProperty = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String selectDBQuery =
|
||||
"SELECT PROPERTY, FEATURE_ID FROM MBL_FEATURE_PROPERTY WHERE PROPERTY_ID = ?";
|
||||
stmt = conn.prepareStatement(selectDBQuery);
|
||||
stmt.setInt(1, propertyId);
|
||||
ResultSet resultSet = stmt.executeQuery();
|
||||
while (resultSet.next()) {
|
||||
featureProperty = new FeatureProperty();
|
||||
featureProperty.setProperty(resultSet.getString(1));
|
||||
featureProperty.setFeatureID(resultSet.getString(2));
|
||||
break;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while fetching property Id - '" +
|
||||
propertyId + "'";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
return featureProperty;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FeatureProperty> getFeaturePropertyOfFeature(String featureId)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
FeatureProperty featureProperty = null;
|
||||
List<FeatureProperty> FeatureProperties = new ArrayList<FeatureProperty>();
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String selectDBQuery =
|
||||
"SELECT PROPERTY_ID,PROPERTY, FEATURE_ID FROM MBL_FEATURE_PROPERTY WHERE FEATURE_ID = ?";
|
||||
stmt = conn.prepareStatement(selectDBQuery);
|
||||
stmt.setString(1, featureId);
|
||||
ResultSet resultSet = stmt.executeQuery();
|
||||
while (resultSet.next()) {
|
||||
featureProperty = new FeatureProperty();
|
||||
featureProperty.setPropertyId(resultSet.getInt(1));
|
||||
featureProperty.setProperty(resultSet.getString(2));
|
||||
featureProperty.setFeatureID(resultSet.getString(3));
|
||||
FeatureProperties.add(featureProperty);
|
||||
}
|
||||
return FeatureProperties;
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while fetching all feature property.'";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
}
|
||||
|
||||
private Connection getConnection() throws MobileDeviceManagementDAOException {
|
||||
try {
|
||||
return dataSource.getConnection();
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while obtaining a connection from the mobile device " +
|
||||
"management metadata repository datasource.";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,151 @@
|
||||
package org.wso2.carbon.device.mgt.mobile.dao.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.OperationDAO;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil;
|
||||
import org.wso2.carbon.device.mgt.mobile.dto.Operation;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* Implementation of OperationDAO
|
||||
*/
|
||||
public class OperationDAOImpl implements OperationDAO {
|
||||
|
||||
private DataSource dataSource;
|
||||
private static final Log log = LogFactory.getLog(OperationDAOImpl.class);
|
||||
|
||||
public OperationDAOImpl(DataSource dataSource) {
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addOperation(Operation operation)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
boolean status = false;
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String createDBQuery =
|
||||
"INSERT INTO MBL_OPERATION(FEATURE_CODE, CREATED_DATE) VALUES ( ?, ?)";
|
||||
|
||||
stmt = conn.prepareStatement(createDBQuery);
|
||||
stmt.setString(1, operation.getFeatureCode());
|
||||
stmt.setInt(2, operation.getCreatedDate());
|
||||
int rows = stmt.executeUpdate();
|
||||
if (rows > 0) {
|
||||
status = true;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while adding feature code - '" +
|
||||
operation.getFeatureCode() + "' to operations table";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateOperation(Operation operation)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
boolean status = false;
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String updateDBQuery =
|
||||
"UPDATE MBL_OPERATION SET FEATURE_CODE = ?, CREATED_DATE = ? WHERE OPERATION_ID = ?";
|
||||
stmt = conn.prepareStatement(updateDBQuery);
|
||||
stmt.setString(1, operation.getFeatureCode());
|
||||
stmt.setInt(2, operation.getCreatedDate());
|
||||
stmt.setInt(3, operation.getOperationId());
|
||||
int rows = stmt.executeUpdate();
|
||||
if (rows > 0) {
|
||||
status = true;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while updating the operation with operation id - '" +
|
||||
operation.getOperationId() + "'";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteOperation(int operationId)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
boolean status = false;
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String deleteDBQuery =
|
||||
"DELETE FROM MBL_OPERATION WHERE OPERATION_ID = ?";
|
||||
stmt = conn.prepareStatement(deleteDBQuery);
|
||||
stmt.setInt(1, operationId);
|
||||
int rows = stmt.executeUpdate();
|
||||
if (rows > 0) {
|
||||
status = true;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while deleting operation with operation Id - ";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Operation getOperation(int operationId)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
Operation operation = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String selectDBQuery =
|
||||
"SELECT OPERATION_ID, FEATURE_CODE, CREATED_DATE FROM MBL_OPERATION WHERE OPERATION_ID = ?";
|
||||
stmt = conn.prepareStatement(selectDBQuery);
|
||||
stmt.setInt(1, operation.getOperationId());
|
||||
ResultSet resultSet = stmt.executeQuery();
|
||||
while (resultSet.next()) {
|
||||
operation = new Operation();
|
||||
operation.setOperationId(resultSet.getInt(1));
|
||||
break;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while fetching operationId - '" +
|
||||
operationId + "'";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
return operation;
|
||||
}
|
||||
|
||||
private Connection getConnection() throws MobileDeviceManagementDAOException {
|
||||
try {
|
||||
return dataSource.getConnection();
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while obtaining a connection from the mobile device " +
|
||||
"management metadata repository datasource.";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
package org.wso2.carbon.device.mgt.mobile.dao.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.OperationPropertyDAO;
|
||||
import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil;
|
||||
import org.wso2.carbon.device.mgt.mobile.dto.OperationProperty;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Implementation of OperationPropertyDAO
|
||||
*/
|
||||
public class OperationPropertyDAOImpl implements OperationPropertyDAO {
|
||||
|
||||
private DataSource dataSource;
|
||||
private static final Log log = LogFactory.getLog(OperationPropertyDAOImpl.class);
|
||||
|
||||
public OperationPropertyDAOImpl(DataSource dataSource) {
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addOperationProperty(OperationProperty operationProperty)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
boolean status = false;
|
||||
Connection conn = null;
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String createDBQuery =
|
||||
"INSERT INTO MBL_OPERATION_PROPERTY(OPERATION_ID, PROPERTY_ID, VALUE) VALUES ( ?, ?, ?)";
|
||||
|
||||
stmt = conn.prepareStatement(createDBQuery);
|
||||
stmt.setInt(1, operationProperty.getOperationId());
|
||||
stmt.setInt(2, operationProperty.getPropertyId());
|
||||
stmt.setString(3, operationProperty.getValue());
|
||||
int rows = stmt.executeUpdate();
|
||||
if (rows > 0) {
|
||||
status = true;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while adding feature property to operation property table";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
} finally {
|
||||
MobileDeviceManagementDAOUtil.cleanupResources(conn, stmt, null);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@Override public boolean updateOperationProperty(OperationProperty operationProperty)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override public boolean deleteOperationProperty(int operationPropertyId)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override public OperationProperty getOperationProperty(String deviceId, int operationId)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override public List<OperationProperty> getAllDeviceOperationOfDevice(String deviceId)
|
||||
throws MobileDeviceManagementDAOException {
|
||||
return null;
|
||||
}
|
||||
|
||||
private Connection getConnection() throws MobileDeviceManagementDAOException {
|
||||
try {
|
||||
return dataSource.getConnection();
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while obtaining a connection from the mobile device " +
|
||||
"management metadata repository datasource.";
|
||||
log.error(msg, e);
|
||||
throw new MobileDeviceManagementDAOException(msg, e);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package org.wso2.carbon.device.mgt.mobile.dto;
|
||||
|
||||
/**
|
||||
* DTO of Operations.
|
||||
*/
|
||||
public class DeviceOperation {
|
||||
String deviceId;
|
||||
int operationId;
|
||||
int sentDate;
|
||||
int receivedDate;
|
||||
|
||||
public String getDeviceId() {
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
public void setDeviceId(String deviceId) {
|
||||
this.deviceId = deviceId;
|
||||
}
|
||||
|
||||
public int getOperationId() {
|
||||
return operationId;
|
||||
}
|
||||
|
||||
public void setOperationId(int operationId) {
|
||||
this.operationId = operationId;
|
||||
}
|
||||
|
||||
public int getSentDate() {
|
||||
return sentDate;
|
||||
}
|
||||
|
||||
public void setSentDate(int sentDate) {
|
||||
this.sentDate = sentDate;
|
||||
}
|
||||
|
||||
public int getReceivedDate() {
|
||||
return receivedDate;
|
||||
}
|
||||
|
||||
public void setReceivedDate(int receivedDate) {
|
||||
this.receivedDate = receivedDate;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package org.wso2.carbon.device.mgt.mobile.dto;
|
||||
|
||||
/**
|
||||
* DTO of operation.
|
||||
*/
|
||||
public class Operation {
|
||||
int operationId;
|
||||
String featureCode;
|
||||
int createdDate;
|
||||
|
||||
public int getOperationId() {
|
||||
return operationId;
|
||||
}
|
||||
|
||||
public void setOperationId(int operationId) {
|
||||
this.operationId = operationId;
|
||||
}
|
||||
|
||||
public String getFeatureCode() {
|
||||
return featureCode;
|
||||
}
|
||||
|
||||
public void setFeatureCode(String featureCode) {
|
||||
this.featureCode = featureCode;
|
||||
}
|
||||
|
||||
public int getCreatedDate() {
|
||||
return createdDate;
|
||||
}
|
||||
|
||||
public void setCreatedDate(int createdDate) {
|
||||
this.createdDate = createdDate;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package org.wso2.carbon.device.mgt.mobile.dto;
|
||||
|
||||
/**
|
||||
* DTO of operation property.
|
||||
*/
|
||||
public class OperationProperty {
|
||||
int operationPropertyId;
|
||||
int getOperationId;
|
||||
int propertyId;
|
||||
String value;
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public int getOperationPropertyId() {
|
||||
return operationPropertyId;
|
||||
}
|
||||
|
||||
public void setOperationPropertyId(int operationPropertyId) {
|
||||
this.operationPropertyId = operationPropertyId;
|
||||
}
|
||||
|
||||
public int getOperationId() {
|
||||
return getOperationId;
|
||||
}
|
||||
|
||||
public void setOperationId(int getOperationId) {
|
||||
this.getOperationId = getOperationId;
|
||||
}
|
||||
|
||||
public int getPropertyId() {
|
||||
return propertyId;
|
||||
}
|
||||
|
||||
public void setPropertyId(int propertyId) {
|
||||
this.propertyId = propertyId;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue