Adding remaining changes

merge-requests/7/head
megala21 7 years ago
parent e26d859236
commit d8ff31b628

@ -23,14 +23,8 @@ package org.wso2.carbon.device.application.mgt.common.exception;
* Exception that will be thrown during Application Category Management. * Exception that will be thrown during Application Category Management.
*/ */
public class ApplicationCategoryManagementException extends ApplicationManagementException { public class ApplicationCategoryManagementException extends ApplicationManagementException {
public ApplicationCategoryManagementException(String message, Throwable throwable) {
super(message, throwable);
setMessage(message);
}
public ApplicationCategoryManagementException(String message) { public ApplicationCategoryManagementException(String message) {
super(message); super(message);
setMessage(message); setMessage(message);
} }
} }

@ -20,7 +20,6 @@ package org.wso2.carbon.device.application.mgt.core.dao;
import org.wso2.carbon.device.application.mgt.common.Application; import org.wso2.carbon.device.application.mgt.common.Application;
import org.wso2.carbon.device.application.mgt.common.ApplicationList; import org.wso2.carbon.device.application.mgt.common.ApplicationList;
import org.wso2.carbon.device.application.mgt.common.Category;
import org.wso2.carbon.device.application.mgt.common.Filter; import org.wso2.carbon.device.application.mgt.common.Filter;
import org.wso2.carbon.device.application.mgt.common.LifecycleStateTransition; import org.wso2.carbon.device.application.mgt.common.LifecycleStateTransition;
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
@ -51,36 +50,111 @@ public interface ApplicationDAO {
*/ */
ApplicationList getApplications(Filter filter, int tenantId) throws ApplicationManagementDAOException; ApplicationList getApplications(Filter filter, int tenantId) throws ApplicationManagementDAOException;
/**
* To get the application with the given uuid
*
* @param uuid UUID of the application to be retrieved.
* @param tenantId ID of the tenant.
* @param userName Name of the user.
* @return the application
* @throws ApplicationManagementDAOException Application Management DAO Exception.
*/
Application getApplication(String uuid, int tenantId, String userName) throws ApplicationManagementDAOException; Application getApplication(String uuid, int tenantId, String userName) throws ApplicationManagementDAOException;
/**
* To get the application id of the application specified by the UUID
*
* @param uuid UUID of the application.
* @param tenantId ID of the tenant.
* @return ID of the Application.
* @throws ApplicationManagementDAOException Application Management DAO Exception.
*/
int getApplicationId(String uuid, int tenantId) throws ApplicationManagementDAOException; int getApplicationId(String uuid, int tenantId) throws ApplicationManagementDAOException;
/**
* To edit the given application.
*
* @param application Application that need to be edited.
* @param tenantId Tenant ID of the Application.
* @return Updated Application.
* @throws ApplicationManagementDAOException Application Management DAO Exception.
*/
Application editApplication(Application application, int tenantId) throws ApplicationManagementDAOException; Application editApplication(Application application, int tenantId) throws ApplicationManagementDAOException;
/**
* To delete the application identified by the UUID
*
* @param uuid UUID of the application.
* @param tenantId ID of tenant which the Application belongs to.
* @throws ApplicationManagementDAOException Application Management DAO Exception.
*/
void deleteApplication(String uuid, int tenantId) throws ApplicationManagementDAOException; void deleteApplication(String uuid, int tenantId) throws ApplicationManagementDAOException;
/**
* To get the application count that satisfies gives search query.
*
* @param filter Application Filter.
* @return count of the applications
* @throws ApplicationManagementDAOException Application Management DAO Exception.
*/
int getApplicationCount(Filter filter) throws ApplicationManagementDAOException; int getApplicationCount(Filter filter) throws ApplicationManagementDAOException;
/**
* To delete the properties of a application.
*
* @param applicationId ID of the application to delete the properties.
* @throws ApplicationManagementDAOException Application Management DAO Exception.
*/
void deleteProperties(int applicationId) throws ApplicationManagementDAOException; void deleteProperties(int applicationId) throws ApplicationManagementDAOException;
/**
* To delete the tags of a application.
*
* @param applicationId ID of the application to delete the tags.
* @throws ApplicationManagementDAOException Application Management DAO Exception.
*/
void deleteTags(int applicationId) throws ApplicationManagementDAOException; void deleteTags(int applicationId) throws ApplicationManagementDAOException;
void changeLifecycle(String applicationUUID, String lifecycleIdentifier, String username, int tenantId) throws /**
ApplicationManagementDAOException; * To change the lifecycle state of the application.
*
List<LifecycleStateTransition> getNextLifeCycleStates(String applicationUUID, int tenantId) throws * @param applicationUUID UUID of the application.
ApplicationManagementDAOException; * @param lifecycleIdentifier New lifecycle state.
* @param username Name of the user.
void updateScreenShotCount(String applicationUUID, int tenantId, int count) throws * @param tenantId ID of the tenant.
ApplicationManagementDAOException; * @throws ApplicationManagementDAOException Application Management DAO Exception.
*/
Category addCategory(Category category) throws ApplicationManagementDAOException; void changeLifecycle(String applicationUUID, String lifecycleIdentifier, String username, int tenantId)
throws ApplicationManagementDAOException;
List<Category> getCategories() throws ApplicationManagementDAOException;
Category getCategory(String name) throws ApplicationManagementDAOException; /**
* To get the next possible lifecycle states for the application.
*
* @param applicationUUID UUID of the application.
* @param tenantId ID of the tenant.
* @return Next possible lifecycle states.
* @throws ApplicationManagementDAOException Application Management DAO Exception.
*/
List<LifecycleStateTransition> getNextLifeCycleStates(String applicationUUID, int tenantId)
throws ApplicationManagementDAOException;
boolean isApplicationExistForCategory(String name) throws ApplicationManagementDAOException; /**
* To update the screen-shot count of a application.
*
* @param applicationUUID UUID of the application.
* @param tenantId ID of the tenant.
* @param count New count of the screen-shots.
* @throws ApplicationManagementDAOException Application Management DAO Exception.
*/
void updateScreenShotCount(String applicationUUID, int tenantId, int count)
throws ApplicationManagementDAOException;
void deleteCategory(String name) throws ApplicationManagementDAOException; /**
* To check whether atleast one application exist under category.
*
* @param categoryName Name of the category.
* @return true if atleast one application exist under the given category, otherwise false.
* @throws ApplicationManagementDAOException Application Management DAO Exception.
*/
boolean isApplicationExist(String categoryName) throws ApplicationManagementDAOException;
} }

@ -18,8 +18,47 @@
*/ */
package org.wso2.carbon.device.application.mgt.core.dao; package org.wso2.carbon.device.application.mgt.core.dao;
import org.wso2.carbon.device.application.mgt.common.Category;
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
import java.util.List;
/** /**
* This is responsible for Application Category related DAO operations. * This is responsible for Application Category related DAO operations.
*/ */
public interface CategoryDAO { public interface CategoryDAO {
/**
* To add a new category.
*
* @param category Category that need to be added.
* @return Newly added category.
* @throws ApplicationManagementDAOException Application Management DAO Exception.
*/
Category addCategory(Category category) throws ApplicationManagementDAOException;
/**
* To get the existing categories.
*
* @return Existing categories.
* @throws ApplicationManagementDAOException Application Management DAO Exception.
*/
List<Category> getCategories() throws ApplicationManagementDAOException;
/**
* To get the category with the given name.
*
* @param name Name of the Application category.
* @return Application Category.
* @throws ApplicationManagementDAOException Application Management DAO Exception.
*/
Category getCategory(String name) throws ApplicationManagementDAOException;
/**
* To delete a particular category.
*
* @param name Name of the category that need to be deleted.
* @throws ApplicationManagementDAOException Application Management DAO Exception.
*/
void deleteCategory(String name) throws ApplicationManagementDAOException;
} }

@ -22,15 +22,11 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.application.mgt.common.exception.UnsupportedDatabaseEngineException; import org.wso2.carbon.device.application.mgt.common.exception.UnsupportedDatabaseEngineException;
import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager; import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager;
import org.wso2.carbon.device.application.mgt.core.dao.ApplicationDAO; import org.wso2.carbon.device.application.mgt.core.dao.*;
import org.wso2.carbon.device.application.mgt.core.dao.ApplicationReleaseDAO;
import org.wso2.carbon.device.application.mgt.core.dao.LifecycleStateDAO;
import org.wso2.carbon.device.application.mgt.core.dao.PlatformDAO;
import org.wso2.carbon.device.application.mgt.core.dao.SubscriptionDAO;
import org.wso2.carbon.device.application.mgt.core.dao.VisibilityDAO;
import org.wso2.carbon.device.application.mgt.core.dao.impl.application.GenericApplicationDAOImpl; import org.wso2.carbon.device.application.mgt.core.dao.impl.application.GenericApplicationDAOImpl;
import org.wso2.carbon.device.application.mgt.core.dao.impl.application.release.GenericApplicationReleaseDAOImpl; import org.wso2.carbon.device.application.mgt.core.dao.impl.application.release.GenericApplicationReleaseDAOImpl;
import org.wso2.carbon.device.application.mgt.core.dao.impl.application.release.OracleApplicationDAOImpl; import org.wso2.carbon.device.application.mgt.core.dao.impl.application.release.OracleApplicationDAOImpl;
import org.wso2.carbon.device.application.mgt.core.dao.impl.category.GenericCategoryDAOImpl;
import org.wso2.carbon.device.application.mgt.core.dao.impl.lifecyclestate.GenericLifecycleStateImpl; import org.wso2.carbon.device.application.mgt.core.dao.impl.lifecyclestate.GenericLifecycleStateImpl;
import org.wso2.carbon.device.application.mgt.core.dao.impl.platform.GenericPlatformDAOImpl; import org.wso2.carbon.device.application.mgt.core.dao.impl.platform.GenericPlatformDAOImpl;
import org.wso2.carbon.device.application.mgt.core.dao.impl.platform.OracleMsSQLPlatformDAOImpl; import org.wso2.carbon.device.application.mgt.core.dao.impl.platform.OracleMsSQLPlatformDAOImpl;
@ -164,6 +160,23 @@ public class DAOFactory {
throw new IllegalStateException("Database engine has not initialized properly."); throw new IllegalStateException("Database engine has not initialized properly.");
} }
/**
* To get the instance of CategoryDAOImplementation of the particular database engine.
* @return {@link org.wso2.carbon.device.application.mgt.core.dao.impl.category.GenericCategoryDAOImpl}
*/
public static CategoryDAO getCategoryDAO() {
if (databaseEngine != null) {
switch (databaseEngine) {
case Constants.DataBaseTypes.DB_TYPE_H2:
case Constants.DataBaseTypes.DB_TYPE_MYSQL:
return new GenericCategoryDAOImpl();
default:
throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine);
}
}
throw new IllegalStateException("Database engine has not initialized properly.");
}
/** /**
* This method initializes the databases by creating the database. * This method initializes the databases by creating the database.
* *

@ -23,7 +23,6 @@ import org.apache.commons.logging.LogFactory;
import org.json.JSONException; import org.json.JSONException;
import org.wso2.carbon.device.application.mgt.common.Application; import org.wso2.carbon.device.application.mgt.common.Application;
import org.wso2.carbon.device.application.mgt.common.ApplicationList; import org.wso2.carbon.device.application.mgt.common.ApplicationList;
import org.wso2.carbon.device.application.mgt.common.Category;
import org.wso2.carbon.device.application.mgt.common.Filter; import org.wso2.carbon.device.application.mgt.common.Filter;
import org.wso2.carbon.device.application.mgt.common.LifecycleStateTransition; import org.wso2.carbon.device.application.mgt.common.LifecycleStateTransition;
import org.wso2.carbon.device.application.mgt.common.Pagination; import org.wso2.carbon.device.application.mgt.common.Pagination;
@ -58,7 +57,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
log.debug("UUID : " + application.getUuid() + " Name : " + application.getName() + " User name : " log.debug("UUID : " + application.getUuid() + " Name : " + application.getName() + " User name : "
+ application.getUser().getUserName()); + application.getUser().getUserName());
} }
Connection conn = null; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
String sql = ""; String sql = "";
@ -114,7 +113,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
log.debug(String.format("Filter: limit=%s, offset=%", filter.getLimit(), filter.getOffset())); log.debug(String.format("Filter: limit=%s, offset=%", filter.getLimit(), filter.getOffset()));
} }
Connection conn = null; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
String sql = ""; String sql = "";
@ -384,7 +383,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
@Override @Override
public List<LifecycleStateTransition> getNextLifeCycleStates(String applicationUUID, int tenantId) public List<LifecycleStateTransition> getNextLifeCycleStates(String applicationUUID, int tenantId)
throws ApplicationManagementDAOException { throws ApplicationManagementDAOException {
Connection connection = null; Connection connection;
PreparedStatement preparedStatement = null; PreparedStatement preparedStatement = null;
ResultSet resultSet = null; ResultSet resultSet = null;
@ -446,147 +445,31 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} }
@Override @Override
public Category addCategory(Category category) throws ApplicationManagementDAOException { public boolean isApplicationExist(String categoryName) throws ApplicationManagementDAOException {
Connection connection;
PreparedStatement statement = null;
String sql = "INSERT INTO APPM_APPLICATION_CATEGORY (NAME, DESCRIPTION) VALUES (?, ?)";
String[] generatedColumns = { "ID" };
ResultSet rs = null;
try {
connection = this.getDBConnection();
statement = connection.prepareStatement(sql, generatedColumns);
statement.setString(1, category.getName());
statement.setString(2, category.getDescription());
statement.executeUpdate();
rs = statement.getGeneratedKeys();
if (rs.next()) {
category.setId(rs.getInt(1));
}
return category;
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException(
"Database connection while trying to update the categroy " + category.getName(), e);
} catch (SQLException e) {
throw new ApplicationManagementDAOException("SQL exception while executing the query '" + sql + "' .", e);
} finally {
Util.cleanupResources(statement, rs);
}
}
@Override
public List<Category> getCategories() throws ApplicationManagementDAOException {
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
String sql = "SELECT * FROM APPM_APPLICATION_CATEGORY";
List<Category> categories = new ArrayList<>();
try {
conn = this.getDBConnection();
stmt = conn.prepareStatement(sql);
rs = stmt.executeQuery();
while (rs.next()) {
Category category = new Category();
category.setId(rs.getInt("ID"));
category.setName(rs.getString("NAME"));
category.setDescription(rs.getString("DESCRIPTION"));
categories.add(category);
}
return categories;
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Database Connection Exception while trying to get the "
+ "application categories", e);
} catch (SQLException e) {
throw new ApplicationManagementDAOException("SQL Exception while trying to get the application "
+ "categories, while executing " + sql, e);
} finally {
Util.cleanupResources(stmt, rs);
}
}
@Override
public Category getCategory(String name) throws ApplicationManagementDAOException {
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
String sql = "SELECT * FROM APPM_APPLICATION_CATEGORY WHERE NAME = ?";
try {
conn = this.getDBConnection();
stmt = conn.prepareStatement(sql);
stmt.setString(1, name);
rs = stmt.executeQuery();
if (rs.next()) {
Category category = new Category();
category.setId(rs.getInt("ID"));
category.setName(rs.getString("NAME"));
category.setDescription(rs.getString("DESCRIPTION"));
return category;
}
return null;
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Database Connection Exception while trying to get the "
+ "application categories", e);
} catch (SQLException e) {
throw new ApplicationManagementDAOException("SQL Exception while trying to get the application "
+ "categories, while executing " + sql, e);
} finally {
Util.cleanupResources(stmt, rs);
}
}
@Override
public boolean isApplicationExistForCategory(String name) throws ApplicationManagementDAOException {
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
String sql = "SELECT * FROM APPM_APPLICATION WHERE APPLICATION_CATEGORY_ID = (SELECT ID FROM " String sql = "SELECT * FROM APPM_APPLICATION WHERE APPLICATION_CATEGORY_ID = (SELECT ID FROM "
+ "APPM_APPLICATION_CATEGORY WHERE NAME = ?)"; + "APPM_APPLICATION_CATEGORY WHERE NAME = ?)";
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setString(1, name); stmt.setString(1, categoryName);
rs = stmt.executeQuery(); rs = stmt.executeQuery();
return rs.next(); return rs.next();
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException( throw new ApplicationManagementDAOException(
"Database Connection Exception while trying to check the " + "applications for teh category " "Database Connection Exception while trying to check the " + "applications for teh category "
+ name, e); + categoryName, e);
} catch (SQLException e) { } catch (SQLException e) {
throw new ApplicationManagementDAOException( throw new ApplicationManagementDAOException(
"SQL Exception while trying to get the application related with categories, while executing " "SQL Exception while trying to get the application related with categories, while executing " + sql,
+ sql, e); e);
} finally { } finally {
Util.cleanupResources(stmt, rs); Util.cleanupResources(stmt, rs);
} }
} }
@Override
public void deleteCategory(String name) throws ApplicationManagementDAOException {
Connection conn;
PreparedStatement stmt = null;
String sql = "DELETE FROM APPM_APPLICATION_CATEGORY WHERE NAME = ?";
try {
conn = this.getDBConnection();
stmt = conn.prepareStatement(sql);
stmt.setString(1, name);
stmt.executeUpdate();
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException(
"Database Connection Exception while trying to delete the category " + name, e);
} catch (SQLException e) {
throw new ApplicationManagementDAOException(
"SQL Exception while trying to delete the category " + name + " while executing the query " +
sql, e);
} finally {
Util.cleanupResources(stmt, null);
}
}
@Override @Override
public Application editApplication(Application application, int tenantId) throws ApplicationManagementDAOException { public Application editApplication(Application application, int tenantId) throws ApplicationManagementDAOException {
Connection conn; Connection conn;
@ -778,7 +661,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
@Override @Override
public int getApplicationId(String uuid, int tenantId) throws ApplicationManagementDAOException { public int getApplicationId(String uuid, int tenantId) throws ApplicationManagementDAOException {
Connection conn = null; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
String sql; String sql;

@ -0,0 +1,151 @@
/*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.device.application.mgt.core.dao.impl.category;
import org.wso2.carbon.device.application.mgt.common.Category;
import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException;
import org.wso2.carbon.device.application.mgt.core.dao.CategoryDAO;
import org.wso2.carbon.device.application.mgt.core.dao.common.Util;
import org.wso2.carbon.device.application.mgt.core.dao.impl.AbstractDAOImpl;
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
/**
* This is the concrete implementation of {@link CategoryDAO}.
*/
public class GenericCategoryDAOImpl extends AbstractDAOImpl implements CategoryDAO {
@Override
public Category addCategory(Category category) throws ApplicationManagementDAOException {
Connection connection;
PreparedStatement statement = null;
String sql = "INSERT INTO APPM_APPLICATION_CATEGORY (NAME, DESCRIPTION) VALUES (?, ?)";
String[] generatedColumns = { "ID" };
ResultSet rs = null;
try {
connection = this.getDBConnection();
statement = connection.prepareStatement(sql, generatedColumns);
statement.setString(1, category.getName());
statement.setString(2, category.getDescription());
statement.executeUpdate();
rs = statement.getGeneratedKeys();
if (rs.next()) {
category.setId(rs.getInt(1));
}
return category;
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException(
"Database connection while trying to update the categroy " + category.getName(), e);
} catch (SQLException e) {
throw new ApplicationManagementDAOException("SQL exception while executing the query '" + sql + "' .", e);
} finally {
Util.cleanupResources(statement, rs);
}
}
@Override
public List<Category> getCategories() throws ApplicationManagementDAOException {
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
String sql = "SELECT * FROM APPM_APPLICATION_CATEGORY";
List<Category> categories = new ArrayList<>();
try {
conn = this.getDBConnection();
stmt = conn.prepareStatement(sql);
rs = stmt.executeQuery();
while (rs.next()) {
Category category = new Category();
category.setId(rs.getInt("ID"));
category.setName(rs.getString("NAME"));
category.setDescription(rs.getString("DESCRIPTION"));
categories.add(category);
}
return categories;
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Database Connection Exception while trying to get the "
+ "application categories", e);
} catch (SQLException e) {
throw new ApplicationManagementDAOException("SQL Exception while trying to get the application "
+ "categories, while executing " + sql, e);
} finally {
Util.cleanupResources(stmt, rs);
}
}
@Override
public Category getCategory(String name) throws ApplicationManagementDAOException {
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
String sql = "SELECT * FROM APPM_APPLICATION_CATEGORY WHERE NAME = ?";
try {
conn = this.getDBConnection();
stmt = conn.prepareStatement(sql);
stmt.setString(1, name);
rs = stmt.executeQuery();
if (rs.next()) {
Category category = new Category();
category.setId(rs.getInt("ID"));
category.setName(rs.getString("NAME"));
category.setDescription(rs.getString("DESCRIPTION"));
return category;
}
return null;
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Database Connection Exception while trying to get the "
+ "application categories", e);
} catch (SQLException e) {
throw new ApplicationManagementDAOException("SQL Exception while trying to get the application "
+ "categories, while executing " + sql, e);
} finally {
Util.cleanupResources(stmt, rs);
}
}
@Override
public void deleteCategory(String name) throws ApplicationManagementDAOException {
Connection conn;
PreparedStatement stmt = null;
String sql = "DELETE FROM APPM_APPLICATION_CATEGORY WHERE NAME = ?";
try {
conn = this.getDBConnection();
stmt = conn.prepareStatement(sql);
stmt.setString(1, name);
stmt.executeUpdate();
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException(
"Database Connection Exception while trying to delete the category " + name, e);
} catch (SQLException e) {
throw new ApplicationManagementDAOException(
"SQL Exception while trying to delete the category " + name + " while executing the query " +
sql, e);
} finally {
Util.cleanupResources(stmt, null);
}
}
}

@ -44,12 +44,13 @@ public class CategoryManagerImpl implements CategoryManager {
"Application category name cannot be null. Application category creation failed."); "Application category name cannot be null. Application category creation failed.");
} }
if (getCategory(category.getName()) != null) { if (getCategory(category.getName()) != null) {
throw new ApplicationCategoryManagementException("Application category wth the name " + category.getName() + " " throw new ApplicationCategoryManagementException(
"Application category wth the name " + category.getName() + " "
+ "exists already. Please select a different name"); + "exists already. Please select a different name");
} }
try { try {
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
Category createdCategory = DAOFactory.getApplicationDAO().addCategory(category); Category createdCategory = DAOFactory.getCategoryDAO().addCategory(category);
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
return createdCategory; return createdCategory;
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
@ -64,7 +65,7 @@ public class CategoryManagerImpl implements CategoryManager {
public List<Category> getCategories() throws ApplicationManagementException { public List<Category> getCategories() throws ApplicationManagementException {
try { try {
ConnectionManagerUtil.openDBConnection(); ConnectionManagerUtil.openDBConnection();
return DAOFactory.getApplicationDAO().getCategories(); return DAOFactory.getCategoryDAO().getCategories();
} finally { } finally {
ConnectionManagerUtil.closeDBConnection(); ConnectionManagerUtil.closeDBConnection();
} }
@ -77,7 +78,7 @@ public class CategoryManagerImpl implements CategoryManager {
} }
try { try {
ConnectionManagerUtil.openDBConnection(); ConnectionManagerUtil.openDBConnection();
return DAOFactory.getApplicationDAO().getCategory(name); return DAOFactory.getCategoryDAO().getCategory(name);
} finally { } finally {
ConnectionManagerUtil.closeDBConnection(); ConnectionManagerUtil.closeDBConnection();
} }
@ -92,15 +93,13 @@ public class CategoryManagerImpl implements CategoryManager {
} }
try { try {
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
boolean isApplicationExistForCategory = DAOFactory.getApplicationDAO().isApplicationExistForCategory(name); boolean isApplicationExistForCategory = DAOFactory.getApplicationDAO().isApplicationExist(name);
if (isApplicationExistForCategory) { if (isApplicationExistForCategory) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
throw new ApplicationCategoryManagementException( throw new ApplicationCategoryManagementException(
"Cannot delete the the category " + name + ". Applications " + "exists for this category"); "Cannot delete the the category " + name + ". Applications " + "exists for this category");
} }
DAOFactory.getCategoryDAO().deleteCategory(name);
DAOFactory.getApplicationDAO().deleteCategory(name);
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
@ -109,5 +108,4 @@ public class CategoryManagerImpl implements CategoryManager {
ConnectionManagerUtil.closeDBConnection(); ConnectionManagerUtil.closeDBConnection();
} }
} }
} }

Loading…
Cancel
Save