|
|
@ -43,115 +43,6 @@ public class FeatureDAOImpl implements FeatureDAO {
|
|
|
|
|
|
|
|
|
|
|
|
private static final Log log = LogFactory.getLog(FeatureDAOImpl.class);
|
|
|
|
private static final Log log = LogFactory.getLog(FeatureDAOImpl.class);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* @Override
|
|
|
|
|
|
|
|
public Feature addFeature(Feature feature) throws FeatureManagerDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Connection conn;
|
|
|
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
|
|
|
ResultSet generatedKeys = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
conn = this.getConnection();
|
|
|
|
|
|
|
|
String query = "INSERT INTO DM_FEATURES (NAME, CODE, DESCRIPTION) VALUES (?, ?, ?)";
|
|
|
|
|
|
|
|
stmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS);
|
|
|
|
|
|
|
|
stmt.setString(1, feature.getName());
|
|
|
|
|
|
|
|
stmt.setString(2, feature.getCode());
|
|
|
|
|
|
|
|
stmt.setString(3, feature.getDescription());
|
|
|
|
|
|
|
|
int affectedRows = stmt.executeUpdate();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug(affectedRows + " feature is added.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
generatedKeys = stmt.getGeneratedKeys();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (generatedKeys.next()) {
|
|
|
|
|
|
|
|
feature.setId(generatedKeys.getInt(1));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while adding feature to the database.";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new FeatureManagerDAOException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, generatedKeys);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return feature;
|
|
|
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* @Override
|
|
|
|
|
|
|
|
public List<Feature> addFeatures(List<Feature> features) throws FeatureManagerDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Connection conn;
|
|
|
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
|
|
|
ResultSet generatedKeys = null;
|
|
|
|
|
|
|
|
List<Feature> featureList = new ArrayList<Feature>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
conn = this.getConnection();
|
|
|
|
|
|
|
|
String query = "INSERT INTO DM_FEATURES (NAME, CODE, DESCRIPTION) VALUES (?, ?, ?)";
|
|
|
|
|
|
|
|
stmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (Feature feature : features) {
|
|
|
|
|
|
|
|
stmt.setString(1, feature.getName());
|
|
|
|
|
|
|
|
stmt.setString(2, feature.getCode());
|
|
|
|
|
|
|
|
stmt.setString(3, feature.getDescription());
|
|
|
|
|
|
|
|
stmt.addBatch();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int[] affectedRows = stmt.executeBatch();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
generatedKeys = stmt.getGeneratedKeys();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug(affectedRows.length + " features are added to the database.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
generatedKeys = stmt.getGeneratedKeys();
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (generatedKeys.next()) {
|
|
|
|
|
|
|
|
features.get(i).setId(generatedKeys.getInt(1));
|
|
|
|
|
|
|
|
i++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while adding feature to the database.";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new FeatureManagerDAOException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, generatedKeys);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return featureList;
|
|
|
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* @Override
|
|
|
|
|
|
|
|
public Feature updateFeature(Feature feature) throws FeatureManagerDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Connection conn;
|
|
|
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
conn = this.getConnection();
|
|
|
|
|
|
|
|
String query = "UPDATE DM_FEATURES SET NAME = ?, CODE = ?, DESCRIPTION = ? WHERE ID = ?";
|
|
|
|
|
|
|
|
stmt = conn.prepareStatement(query);
|
|
|
|
|
|
|
|
stmt.setString(1, feature.getName());
|
|
|
|
|
|
|
|
stmt.setString(2, feature.getCode());
|
|
|
|
|
|
|
|
stmt.setString(3, feature.getDescription());
|
|
|
|
|
|
|
|
stmt.setInt(4, feature.getId());
|
|
|
|
|
|
|
|
stmt.executeUpdate();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while updating feature " + feature.getName() + " (Feature Name) to the
|
|
|
|
|
|
|
|
database.";
|
|
|
|
|
|
|
|
log.error(msg, e);
|
|
|
|
|
|
|
|
throw new FeatureManagerDAOException(msg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
PolicyManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return feature;
|
|
|
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public ProfileFeature addProfileFeature(ProfileFeature feature, int profileId) throws FeatureManagerDAOException {
|
|
|
|
public ProfileFeature addProfileFeature(ProfileFeature feature, int profileId) throws FeatureManagerDAOException {
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
@ -247,7 +138,6 @@ public class FeatureDAOImpl implements FeatureDAO {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean deleteFeaturesOfProfile(Profile profile) throws FeatureManagerDAOException {
|
|
|
|
public boolean deleteFeaturesOfProfile(Profile profile) throws FeatureManagerDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
Connection conn;
|
|
|
|
Connection conn;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
@ -258,9 +148,10 @@ public class FeatureDAOImpl implements FeatureDAO {
|
|
|
|
stmt = conn.prepareStatement(query);
|
|
|
|
stmt = conn.prepareStatement(query);
|
|
|
|
stmt.setInt(1, profile.getProfileId());
|
|
|
|
stmt.setInt(1, profile.getProfileId());
|
|
|
|
stmt.setInt(2, tenantId);
|
|
|
|
stmt.setInt(2, tenantId);
|
|
|
|
stmt.executeUpdate();
|
|
|
|
if (stmt.executeUpdate() > 0) {
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new FeatureManagerDAOException("Error occurred while deleting the feature related to a profile.", e);
|
|
|
|
throw new FeatureManagerDAOException("Error occurred while deleting the feature related to a profile.", e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
@ -270,7 +161,6 @@ public class FeatureDAOImpl implements FeatureDAO {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean deleteFeaturesOfProfile(int profileId) throws FeatureManagerDAOException {
|
|
|
|
public boolean deleteFeaturesOfProfile(int profileId) throws FeatureManagerDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
Connection conn;
|
|
|
|
Connection conn;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
@ -280,9 +170,10 @@ public class FeatureDAOImpl implements FeatureDAO {
|
|
|
|
stmt = conn.prepareStatement(query);
|
|
|
|
stmt = conn.prepareStatement(query);
|
|
|
|
stmt.setInt(1, profileId);
|
|
|
|
stmt.setInt(1, profileId);
|
|
|
|
stmt.setInt(2, tenantId);
|
|
|
|
stmt.setInt(2, tenantId);
|
|
|
|
stmt.executeUpdate();
|
|
|
|
if (stmt.executeUpdate() > 0) {
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new FeatureManagerDAOException("Error occurred while deleting the feature related to a profile.", e);
|
|
|
|
throw new FeatureManagerDAOException("Error occurred while deleting the feature related to a profile.", e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
@ -448,7 +339,6 @@ public class FeatureDAOImpl implements FeatureDAO {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean deleteFeature(int featureId) throws FeatureManagerDAOException {
|
|
|
|
public boolean deleteFeature(int featureId) throws FeatureManagerDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
Connection conn;
|
|
|
|
Connection conn;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
@ -459,9 +349,10 @@ public class FeatureDAOImpl implements FeatureDAO {
|
|
|
|
stmt = conn.prepareStatement(query);
|
|
|
|
stmt = conn.prepareStatement(query);
|
|
|
|
stmt.setInt(1, featureId);
|
|
|
|
stmt.setInt(1, featureId);
|
|
|
|
stmt.setInt(2, tenantId);
|
|
|
|
stmt.setInt(2, tenantId);
|
|
|
|
stmt.executeUpdate();
|
|
|
|
if(stmt.executeUpdate() > 0) {
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new FeatureManagerDAOException("Unable to delete the feature " + featureId + " (Feature ID) " +
|
|
|
|
throw new FeatureManagerDAOException("Unable to delete the feature " + featureId + " (Feature ID) " +
|
|
|
|
"from database.", e);
|
|
|
|
"from database.", e);
|
|
|
@ -471,7 +362,6 @@ public class FeatureDAOImpl implements FeatureDAO {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Connection getConnection() throws FeatureManagerDAOException {
|
|
|
|
private Connection getConnection() throws FeatureManagerDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
return PolicyManagementDAOFactory.getConnection();
|
|
|
|
return PolicyManagementDAOFactory.getConnection();
|
|
|
|
} catch (PolicyManagerDAOException e) {
|
|
|
|
} catch (PolicyManagerDAOException e) {
|
|
|
|