Refactored Application-Mgt DAO layer.

4.x.x
Harshan Liyanage 8 years ago
parent 36d82c85ef
commit 0d3598d214

@ -23,7 +23,7 @@ import org.wso2.carbon.device.application.mgt.common.Application;
import org.wso2.carbon.device.application.mgt.common.Filter;
import org.wso2.carbon.device.application.mgt.common.ApplicationList;
public interface ApplicationsDAO {
public interface ApplicationDAO {
Application createApplication(Application application) throws ApplicationManagementDAOException;

@ -1,22 +0,0 @@
/*
* 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;
public interface ResourceTypesDAO {
}

@ -0,0 +1,22 @@
/*
* 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;
public interface SubscriptionDAO {
}

@ -1,22 +0,0 @@
/*
* 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;
public interface SubscriptionsDAO {
}

@ -0,0 +1,22 @@
/*
* 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;
public interface VisibilityDAO {
}

@ -1,27 +0,0 @@
/*
* 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.common;
import org.wso2.carbon.device.application.mgt.core.dao.*;
import org.wso2.carbon.device.application.mgt.common.LifecycleState;
public interface ApplicationManagementDAO extends ApplicationReleasesDAO, ApplicationsDAO, CategoriesDAO, CommentsDAO,
LifecycleStatesDAO, PlatformsDAO, ResourceTypesDAO, SubscriptionsDAO, VisibilitiesDAO {
}

@ -22,37 +22,45 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.application.mgt.common.exception.UnsupportedDatabaseEngineException;
import org.wso2.carbon.device.application.mgt.core.config.datasource.DataSourceConfig;
import org.wso2.carbon.device.application.mgt.core.dao.impl.GenericAppManagementDAO;
import org.wso2.carbon.device.application.mgt.core.dao.ApplicationDAO;
import org.wso2.carbon.device.application.mgt.core.dao.impl.application.GenericApplicationDAOImpl;
import org.wso2.carbon.device.application.mgt.core.util.ApplicationManagerConstants;
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
import javax.sql.DataSource;
/**
* This class intends to act as the primary entity that hides all DAO instantiation related complexities and logic so
* that the business objection handling layer doesn't need to be aware of the same providing seamless plug-ability of
* different data sources, connection acquisition mechanisms as well as different forms of DAO implementations to the
* high-level implementations that require Application management related metadata persistence.
*/
public class ApplicationManagementDAOFactory {
private static String databaseEngine;
private static final Log log = LogFactory.getLog(ApplicationManagementDAOFactory.class);
public static ApplicationManagementDAO getApplicationManagementDAO(){
public static void init(DataSourceConfig config) {
ConnectionManagerUtil.resolveDataSource(config);
databaseEngine = ConnectionManagerUtil.getDatabaseType();
}
public static void init(DataSource dtSource) {
ConnectionManagerUtil.setDataSource(dtSource);
databaseEngine = ConnectionManagerUtil.getDatabaseType();
}
public static ApplicationDAO getApplicationDAO(){
if (databaseEngine != null) {
switch (databaseEngine) {
case ApplicationManagerConstants.DataBaseTypes.DB_TYPE_H2:
case ApplicationManagerConstants.DataBaseTypes.DB_TYPE_MYSQL:
return new GenericAppManagementDAO();
return new GenericApplicationDAOImpl();
default:
throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine);
}
}
throw new IllegalStateException("Database engine has not initialized properly.");
}
public static void init(DataSourceConfig config) {
ConnectionManagerUtil.resolveDataSource(config);
databaseEngine = ConnectionManagerUtil.getDatabaseType();
}
public static void init(DataSource dtSource) {
ConnectionManagerUtil.setDataSource(dtSource);
databaseEngine = ConnectionManagerUtil.getDatabaseType();
}
}

@ -0,0 +1,53 @@
/*
* 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;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.application.mgt.common.Application;
import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException;
import org.wso2.carbon.device.application.mgt.core.dao.ApplicationDAO;
import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOException;
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
import java.sql.Connection;
public abstract class AbstractApplicationDAOImpl implements ApplicationDAO {
private static final Log log = LogFactory.getLog(AbstractApplicationDAOImpl.class);
@Override
public Application createApplication(Application application) throws ApplicationManagementDAOException {
return null;
}
@Override
public Application editApplication(Application application) throws ApplicationManagementDAOException {
return null;
}
@Override
public void deleteApplication(Application application) throws ApplicationManagementDAOException {
}
private Connection getConnection() throws DBConnectionException {
return ConnectionManagerUtil.getConnection();
}
}

@ -1,35 +1,34 @@
/*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* 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
* 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.
* 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;
package org.wso2.carbon.device.application.mgt.core.dao.impl.application;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.json.JSONException;
import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException;
import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAO;
import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOException;
import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOFactory;
import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOUtil;
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.Filter;
import org.wso2.carbon.device.application.mgt.common.Pagination;
import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException;
import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOException;
import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOUtil;
import org.wso2.carbon.device.application.mgt.core.dao.impl.AbstractApplicationDAOImpl;
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
import java.sql.Connection;
@ -39,14 +38,12 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
public class GenericAppManagementDAO implements ApplicationManagementDAO {
private static final Log log = LogFactory.getLog(ApplicationManagementDAO.class);
/**
* This class holds the generic implementation of ApplicationDAO which can be used to support ANSI db syntax.
*/
public class GenericApplicationDAOImpl extends AbstractApplicationDAOImpl {
@Override
public Application createApplication(Application application) throws ApplicationManagementDAOException {
return null;
}
private static final Log log = LogFactory.getLog(GenericApplicationDAOImpl.class);
@Override
public ApplicationList getApplications(Filter filter) throws ApplicationManagementDAOException {
@ -75,7 +72,7 @@ public class GenericAppManagementDAO implements ApplicationManagementDAO {
conn = this.getConnection();
sql += "SELECT SQL_CALC_FOUND_ROWS APP.*, APL.NAME AS APL_NAME, APL.IDENTIFIER AS APL_IDENTIFIER," +
sql += "SELECT SQL_CALC_FOUND_ROWS APP.* , APL.NAME AS APL_NAME, APL.IDENTIFIER AS APL_IDENTIFIER," +
" CAT.NAME AS CAT_NAME ";
sql += "FROM APPM_APPLICATION AS APP ";
sql += "INNER JOIN APPM_PLATFORM_APPLICATION_MAPPING AS APM ON APP.PLATFORM_APPLICATION_MAPPING_ID = APM.ID ";
@ -120,6 +117,8 @@ public class GenericAppManagementDAO implements ApplicationManagementDAO {
ResultSet rsTags = stmt.executeQuery();
applications.add(ApplicationManagementDAOUtil.loadApplication(rs, rsProperties, rsTags));
ApplicationManagementDAOUtil.cleanupResources(null, rsProperties);
ApplicationManagementDAOUtil.cleanupResources(null, rsTags);
length++;
}
@ -138,17 +137,6 @@ public class GenericAppManagementDAO implements ApplicationManagementDAO {
ApplicationManagementDAOUtil.cleanupResources(stmt, rs);
}
return applicationList;
}
@Override
public Application editApplication(Application application) throws ApplicationManagementDAOException {
return null;
}
@Override
public void deleteApplication(Application application) throws ApplicationManagementDAOException {
}
private Connection getConnection() throws DBConnectionException {

@ -19,7 +19,6 @@
package org.wso2.carbon.device.application.mgt.core.internal;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationManagementService;
import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAO;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
public class ApplicationManagementDataHolder {

@ -26,7 +26,6 @@ import org.wso2.carbon.device.application.mgt.common.services.ApplicationManagem
import org.wso2.carbon.device.application.mgt.core.services.impl.ApplicationManagementServiceImpl;
import org.wso2.carbon.device.application.mgt.core.config.ApplicationConfigurationManager;
import org.wso2.carbon.device.application.mgt.core.config.datasource.DataSourceConfig;
import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAO;
import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOFactory;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;

@ -26,13 +26,11 @@ import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManage
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.Filter;
import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAO;
import org.wso2.carbon.device.application.mgt.core.dao.ApplicationDAO;
import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOException;
import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOFactory;
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
import java.sql.SQLException;
public class ApplicationManagementServiceImpl implements ApplicationManagementService {
private static final Log log = LogFactory.getLog(ApplicationManagementServiceImpl.class);
@ -46,8 +44,8 @@ public class ApplicationManagementServiceImpl implements ApplicationManagementSe
public ApplicationList getApplications(Filter filter) throws ApplicationManagerException {
try {
ConnectionManagerUtil.openConnection();
ApplicationManagementDAO applicationManagementDAO = ApplicationManagementDAOFactory.getApplicationManagementDAO();
return applicationManagementDAO.getApplications(filter);
ApplicationDAO applicationDAO = ApplicationManagementDAOFactory.getApplicationDAO();
return applicationDAO.getApplications(filter);
} catch (ApplicationManagementDAOException e) {
throw new ApplicationManagerException("Error occurred while obtaining the applications for " +
"the given filter.", e);

Loading…
Cancel
Save