|
|
|
@ -20,10 +20,12 @@ package org.wso2.carbon.device.mgt.mobile.impl.android.dao.impl;
|
|
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.Feature;
|
|
|
|
|
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOException;
|
|
|
|
|
import org.wso2.carbon.device.mgt.mobile.dao.MobileDeviceManagementDAOFactory;
|
|
|
|
|
import org.wso2.carbon.device.mgt.mobile.dao.MobileFeatureDAO;
|
|
|
|
|
import org.wso2.carbon.device.mgt.mobile.dao.util.MobileDeviceManagementDAOUtil;
|
|
|
|
|
import org.wso2.carbon.device.mgt.mobile.impl.android.dao.FeatureDAO;
|
|
|
|
|
import org.wso2.carbon.device.mgt.mobile.dto.MobileFeature;
|
|
|
|
|
import org.wso2.carbon.device.mgt.mobile.impl.android.dao.FeatureManagementDAOException;
|
|
|
|
|
import org.wso2.carbon.device.mgt.mobile.impl.android.dao.FeatureManagementDAOFactory;
|
|
|
|
|
import org.wso2.carbon.device.mgt.mobile.util.MobileDeviceManagementUtil;
|
|
|
|
|
|
|
|
|
|
import java.sql.Connection;
|
|
|
|
|
import java.sql.PreparedStatement;
|
|
|
|
@ -32,53 +34,77 @@ import java.sql.SQLException;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
public class FeatureDAOImpl implements FeatureDAO {
|
|
|
|
|
public class FeatureDAOImpl implements MobileFeatureDAO {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void addFeature(Feature feature) throws FeatureManagementDAOException {
|
|
|
|
|
public boolean addFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException {
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
boolean status = false;
|
|
|
|
|
try {
|
|
|
|
|
Connection conn = FeatureManagementDAOFactory.getConnection();
|
|
|
|
|
Connection conn = MobileDeviceManagementDAOFactory.getConnection();
|
|
|
|
|
String sql = "INSERT INTO AD_FEATURE(CODE, NAME, DESCRIPTION) VALUES (?, ?, ?)";
|
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
|
stmt.setString(1, feature.getCode());
|
|
|
|
|
stmt.setString(2, feature.getName());
|
|
|
|
|
stmt.setString(3, feature.getDescription());
|
|
|
|
|
stmt.setString(1, mobileFeature.getCode());
|
|
|
|
|
stmt.setString(2, mobileFeature.getName());
|
|
|
|
|
stmt.setString(3, mobileFeature.getDescription());
|
|
|
|
|
stmt.executeUpdate();
|
|
|
|
|
status = true;
|
|
|
|
|
status = true;
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
throw new FeatureManagementDAOException("Error occurred while adding feature '" +
|
|
|
|
|
feature.getName() + "' into the metadata repository", e);
|
|
|
|
|
throw new org.wso2.carbon.device.mgt.mobile.impl.ios.dao.FeatureManagementDAOException(
|
|
|
|
|
"Error occurred while adding feature '" +
|
|
|
|
|
mobileFeature.getName() + "' into the metadata repository", e);
|
|
|
|
|
} finally {
|
|
|
|
|
MobileDeviceManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
|
}
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void removeFeature(String code) throws FeatureManagementDAOException {
|
|
|
|
|
public boolean updateFeature(MobileFeature mobileFeature) throws MobileDeviceManagementDAOException {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean deleteFeatureById(int mblFeatureId) throws MobileDeviceManagementDAOException {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean deleteFeatureByCode(String mblFeatureCode) throws MobileDeviceManagementDAOException {
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
boolean status = false;
|
|
|
|
|
try {
|
|
|
|
|
Connection conn = FeatureManagementDAOFactory.getConnection();
|
|
|
|
|
Connection conn = MobileDeviceManagementDAOFactory.getConnection();
|
|
|
|
|
String sql = "DELETE FROM AD_FEATURE WHERE CODE = ?";
|
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
|
stmt.setString(1, code);
|
|
|
|
|
stmt.setString(1, mblFeatureCode);
|
|
|
|
|
stmt.execute();
|
|
|
|
|
status = true;
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
throw new FeatureManagementDAOException("Error occurred while adding feature '" +
|
|
|
|
|
code + "' into the metadata repository", e);
|
|
|
|
|
throw new org.wso2.carbon.device.mgt.mobile.impl.ios.dao.FeatureManagementDAOException(
|
|
|
|
|
"Error occurred while adding feature '" +
|
|
|
|
|
mblFeatureCode + "' into the metadata repository", e);
|
|
|
|
|
} finally {
|
|
|
|
|
MobileDeviceManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
|
}
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public MobileFeature getFeatureById(int mblFeatureId) throws MobileDeviceManagementDAOException {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Feature getFeature(String code) throws FeatureManagementDAOException {
|
|
|
|
|
public MobileFeature getFeatureByCode(String mblFeatureCode) throws MobileDeviceManagementDAOException {
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
ResultSet rs = null;
|
|
|
|
|
try {
|
|
|
|
|
Connection conn = FeatureManagementDAOFactory.getConnection();
|
|
|
|
|
Connection conn = MobileDeviceManagementDAOFactory.getConnection();
|
|
|
|
|
String sql = "SELECT ID, CODE, NAME, DESCRIPTION FROM AD_FEATURE WHERE CODE = ?";
|
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
|
stmt.setString(1, code);
|
|
|
|
|
stmt.setString(1, mblFeatureCode);
|
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
|
|
|
|
|
|
Feature feature = null;
|
|
|
|
@ -89,25 +115,35 @@ public class FeatureDAOImpl implements FeatureDAO {
|
|
|
|
|
feature.setName(rs.getString("NAME"));
|
|
|
|
|
feature.setDescription(rs.getString("DESCRIPTION"));
|
|
|
|
|
}
|
|
|
|
|
return feature;
|
|
|
|
|
MobileFeature mobileFeature = MobileDeviceManagementUtil.convertToMobileFeature(feature);
|
|
|
|
|
return mobileFeature;
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
throw new FeatureManagementDAOException("Error occurred while retrieving feature metadata '" +
|
|
|
|
|
code + "' from the feature metadata repository", e);
|
|
|
|
|
throw new org.wso2.carbon.device.mgt.mobile.impl.ios.dao.FeatureManagementDAOException(
|
|
|
|
|
"Error occurred while retrieving feature metadata '" +
|
|
|
|
|
mblFeatureCode + "' from the feature metadata repository", e);
|
|
|
|
|
} finally {
|
|
|
|
|
MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<Feature> getFeatures() throws FeatureManagementDAOException {
|
|
|
|
|
public List<MobileFeature> getFeatureByDeviceType(String deviceType)
|
|
|
|
|
throws MobileDeviceManagementDAOException {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<MobileFeature> getAllFeatures() throws MobileDeviceManagementDAOException {
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
ResultSet rs = null;
|
|
|
|
|
List<Feature> features = new ArrayList<Feature>();
|
|
|
|
|
List<MobileFeature> features = new ArrayList<MobileFeature>();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
Connection conn = FeatureManagementDAOFactory.getConnection();
|
|
|
|
|
Connection conn = MobileDeviceManagementDAOFactory.getConnection();
|
|
|
|
|
String sql = "SELECT ID, CODE, NAME, DESCRIPTION FROM AD_FEATURE";
|
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
|
MobileFeature mobileFeature;
|
|
|
|
|
|
|
|
|
|
while (rs.next()) {
|
|
|
|
|
Feature feature = new Feature();
|
|
|
|
@ -115,6 +151,8 @@ public class FeatureDAOImpl implements FeatureDAO {
|
|
|
|
|
feature.setCode(rs.getString("CODE"));
|
|
|
|
|
feature.setName(rs.getString("NAME"));
|
|
|
|
|
feature.setDescription(rs.getString("DESCRIPTION"));
|
|
|
|
|
mobileFeature = MobileDeviceManagementUtil.convertToMobileFeature(feature);
|
|
|
|
|
features.add(mobileFeature);
|
|
|
|
|
}
|
|
|
|
|
return features;
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
@ -124,5 +162,4 @@ public class FeatureDAOImpl implements FeatureDAO {
|
|
|
|
|
MobileDeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|