From 71aa6762ac49286684f0f7e99b9c8a37e5743867 Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Mon, 19 Mar 2018 18:41:23 +0530 Subject: [PATCH] Refactor APPM DAO Layer Refactored the APPM DAO layer. Further verified and added required functionality to compatible with other DBMS, such as Oracle, PostgreSQL, MSSQL --- .../mgt/core/config/ConfigurationManager.java | 1 - .../mgt/core/dao/ApplicationReleaseDAO.java | 2 +- .../ApplicationManagementDAOFactory.java | 8 +- .../GenericApplicationDAOImpl.java | 41 +++--- .../application/OracleApplicationDAOImpl.java | 127 ++++++++++++++++++ .../GenericApplicationReleaseDAOImpl.java | 2 +- .../release/OracleApplicationDAOImpl.java | 76 ----------- ...java => GenericLifecycleStateDAOImpl.java} | 5 +- .../visibility/GenericVisibilityDAOImpl.java | 21 ++- .../mgt/core/impl/ApplicationManagerImpl.java | 2 +- 10 files changed, 163 insertions(+), 122 deletions(-) create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/OracleApplicationDAOImpl.java delete mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/release/OracleApplicationDAOImpl.java rename components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/lifecyclestate/{GenericLifecycleStateImpl.java => GenericLifecycleStateDAOImpl.java} (97%) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/ConfigurationManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/ConfigurationManager.java index 90675e0102..4e5ae24022 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/ConfigurationManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/ConfigurationManager.java @@ -97,5 +97,4 @@ public class ConfigurationManager { } throw new InvalidConfigurationException("Expecting an extension with name - " + extName + " , but not found!"); } - } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationReleaseDAO.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationReleaseDAO.java index 0d21468ddc..12a0a793d2 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationReleaseDAO.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationReleaseDAO.java @@ -62,7 +62,7 @@ public interface ApplicationReleaseDAO { * @return list of the application releases * @throws ApplicationManagementDAOException Application Management DAO Exception. */ - List getApplicationReleases(String applicationName, String applicationType, int tenantId) throws + List getReleases(String applicationName, String applicationType, int tenantId) throws ApplicationManagementDAOException; /** diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/ApplicationManagementDAOFactory.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/ApplicationManagementDAOFactory.java index 287f9b12f8..0ab4126a1e 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/ApplicationManagementDAOFactory.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/ApplicationManagementDAOFactory.java @@ -26,8 +26,8 @@ import org.wso2.carbon.device.application.mgt.core.dao.*; import org.wso2.carbon.device.application.mgt.core.dao.impl.Comment.CommentDAOImpl; 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.OracleApplicationDAOImpl; -import org.wso2.carbon.device.application.mgt.core.dao.impl.lifecyclestate.GenericLifecycleStateImpl; +import org.wso2.carbon.device.application.mgt.core.dao.impl.application.OracleApplicationDAOImpl; +import org.wso2.carbon.device.application.mgt.core.dao.impl.lifecyclestate.GenericLifecycleStateDAOImpl; import org.wso2.carbon.device.application.mgt.core.dao.impl.subscription.GenericSubscriptionDAOImpl; import org.wso2.carbon.device.application.mgt.core.dao.impl.visibility.GenericVisibilityDAOImpl; import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; @@ -79,7 +79,7 @@ public class ApplicationManagementDAOFactory { case Constants.DataBaseTypes.DB_TYPE_MYSQL: case Constants.DataBaseTypes.DB_TYPE_POSTGRESQL: case Constants.DataBaseTypes.DB_TYPE_ORACLE: - return new GenericLifecycleStateImpl(); + return new GenericLifecycleStateDAOImpl(); default: throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine); } @@ -116,6 +116,8 @@ public class ApplicationManagementDAOFactory { switch (databaseEngine) { case Constants.DataBaseTypes.DB_TYPE_H2: case Constants.DataBaseTypes.DB_TYPE_MYSQL: + case Constants.DataBaseTypes.DB_TYPE_POSTGRESQL: + case Constants.DataBaseTypes.DB_TYPE_ORACLE: return new GenericVisibilityDAOImpl(); default: throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java index 270ad8dd3f..d081f618c1 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java @@ -175,7 +175,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic "AP_UNRESTRICTED_ROLES.ROLE " + "AS APP_UNRESTRICTED_ROLES FROM ((AP_APP LEFT JOIN AP_APP_TAG ON AP_APP.ID = AP_APP_TAG.AP_APP_ID) " + "LEFT JOIN AP_UNRESTRICTED_ROLES ON AP_APP.ID = AP_UNRESTRICTED_ROLES.AP_APP_ID) " - + "WHERE AP_APP.TENANT_ID = ?"; + + "WHERE AP_APP.TENANT_ID = ? AND AP_APP.STATUS != ?"; if (filter == null) { @@ -204,20 +204,21 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic conn = this.getDBConnection(); stmt = conn.prepareStatement(sql); stmt.setInt(1, tenantId); + stmt.setString(2, AppLifecycleState.REMOVED.toString()); if (filter.getAppType() != null) { - stmt.setString(2, filter.getAppType()); + stmt.setString(3, filter.getAppType()); } if (filter.getAppName() != null) { if (filter.isFullMatch()) { - stmt.setString(3, filter.getAppName().toLowerCase()); + stmt.setString(4, filter.getAppName().toLowerCase()); } else { - stmt.setString(3, "%" + filter.getAppName().toLowerCase() + "%"); + stmt.setString(4, "%" + filter.getAppName().toLowerCase() + "%"); } } - stmt.setInt(4, filter.getLimit()); - stmt.setInt(5, filter.getOffset()); + stmt.setInt(5, filter.getLimit()); + stmt.setInt(6, filter.getOffset()); rs = stmt.executeQuery(); applicationList.setApplications(Util.loadApplications(rs)); applicationList.setPagination(pagination); @@ -254,7 +255,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic conn = this.getDBConnection(); sql += "SELECT APP_RELEASE.UUID AS UUID FROM AP_APP_RELEASE AS APP_RELEASE, AP_APP_LIFECYCLE_STATE " + "AS LIFECYCLE WHERE APP_RELEASE.AP_APP_ID=? AND APP_RELEASE.ID = LIFECYCLE.AP_APP_RELEASE_ID " - + "AND LIFECYCLE.CURRENT_STATE = ? order by APP_RELEASE.ID DESC;"; + + "AND LIFECYCLE.CURRENT_STATE = ? ORDER BY APP_RELEASE.ID DESC;"; stmt = conn.prepareStatement(sql); stmt.setInt(1, appId); @@ -333,12 +334,9 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic conn = this.getDBConnection(); String sql = "SELECT AP_APP.ID AS APP_ID, AP_APP.NAME AS APP_NAME, AP_APP.TYPE AS APP_TYPE, AP_APP.APP_CATEGORY " - + - "AS APP_CATEGORY, AP_APP.IS_FREE AS IS_FREE, AP_APP.RESTRICTED AS RESTRICTED, AP_APP_TAG" + - ".TAG AS " + - "APP_TAG, AP_UNRESTRICTED_ROLES.ROLE AS AS ROLE FROM AP_APP, AP_APP_TAG, " + - "AP_UNRESTRICTED_ROLES " + - "WHERE AP_APP.NAME=? AND AP_APP.TYPE= ? AND AP_APP.TENANT_ID=?;"; + + "AS APP_CATEGORY, AP_APP.IS_FREE AS IS_FREE, AP_APP.RESTRICTED AS RESTRICTED, " + + "AP_APP_TAG.TAG AS APP_TAG, AP_UNRESTRICTED_ROLES.ROLE AS ROLE FROM AP_APP, AP_APP_TAG, " + + "AP_UNRESTRICTED_ROLES WHERE AP_APP.NAME=? AND AP_APP.TYPE= ? AND AP_APP.TENANT_ID=?;"; stmt = conn.prepareStatement(sql); stmt.setString(1, appName); @@ -378,13 +376,10 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic try { conn = this.getDBConnection(); String sql = - "SELECT AP_APP.ID AS APP_ID, AP_APP.NAME AS APP_NAME, AP_APP.TYPE AS APP_TYPE, AP_APP" + - ".APP_CATEGORY " + - "AS APP_CATEGORY, AP_APP.IS_FREE AS IS_FREE, AP_APP.RESTRICTED AS RESTRICTED, AP_APP_TAG" + - ".TAG AS APP_TAG, " + - "AP_UNRESTRICTED_ROLES.ROLE AS ROLE FROM AP_APP, AP_APP_TAG, AP_UNRESTRICTED_ROLES WHERE " + - "AP_APP.ID=?" + - " AND AP_APP.TENANT_ID=?;"; + "SELECT AP_APP.ID AS APP_ID, AP_APP.NAME AS APP_NAME, AP_APP.TYPE AS APP_TYPE, AP_APP.APP_CATEGORY " + + "AS APP_CATEGORY, AP_APP.IS_FREE AS IS_FREE, AP_APP.RESTRICTED AS RESTRICTED, AP_APP_TAG" + + ".TAG AS APP_TAG, AP_UNRESTRICTED_ROLES.ROLE AS ROLE FROM AP_APP, AP_APP_TAG, " + + "AP_UNRESTRICTED_ROLES WHERE AP_APP.ID=? AND AP_APP.TENANT_ID=?;"; stmt = conn.prepareStatement(sql); stmt.setInt(1, applicationId); @@ -424,10 +419,8 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic conn = this.getDBConnection(); String sql = "SELECT AP_APP.ID AS APP_ID, AP_APP.NAME AS APP_NAME, AP_APP.TYPE AS APP_TYPE, AP_APP.APP_CATEGORY " - + - "AS APP_CATEGORY, AP_APP.IS_FREE, AP_APP_TAG.TAG, AP_UNRESTRICTED_ROLES.ROLE AS RELESE_ID" + - " FROM " - + "AP_APP, AP_APP_TAG, AP_UNRESTRICTED_ROLES WHERE AP_APP.ID=?;"; + + "AS APP_CATEGORY, AP_APP.IS_FREE, AP_APP_TAG.TAG, AP_UNRESTRICTED_ROLES.ROLE AS RELESE_ID" + + " FROM AP_APP, AP_APP_TAG, AP_UNRESTRICTED_ROLES WHERE AP_APP.ID = ?;"; stmt = conn.prepareStatement(sql); stmt.setInt(1, appId); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/OracleApplicationDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/OracleApplicationDAOImpl.java new file mode 100644 index 0000000000..f7c15cf0fe --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/OracleApplicationDAOImpl.java @@ -0,0 +1,127 @@ +/* + * 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.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.AppLifecycleState; +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.Util; +import org.wso2.carbon.device.application.mgt.core.dao.impl.application.GenericApplicationDAOImpl; +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; + +/** + * This is a ApplicationDAO Implementation specific to Oracle. + */ +public class OracleApplicationDAOImpl extends GenericApplicationDAOImpl { + + private static final Log log = LogFactory.getLog(OracleApplicationDAOImpl.class); + + @Override + public ApplicationList getApplications(Filter filter, int tenantId) throws ApplicationManagementDAOException { + if (log.isDebugEnabled()) { + log.debug("Getting application data from the database"); + log.debug(String.format("Filter: limit=%s, offset=%s", filter.getLimit(), filter.getOffset())); + } + + Connection conn; + PreparedStatement stmt = null; + ResultSet rs = null; + ApplicationList applicationList = new ApplicationList(); + Pagination pagination = new Pagination(); + String sql = "SELECT AP_APP.ID AS APP_ID, AP_APP.NAME AS APP_NAME, AP_APP.TYPE AS APP_TYPE, AP_APP.APP_CATEGORY" + + " AS APP_CATEGORY, AP_APP.IS_FREE, AP_APP.RESTRICTED, AP_APP_TAG.TAG AS APP_TAG, " + + "AP_UNRESTRICTED_ROLES.ROLE AS APP_UNRESTRICTED_ROLES FROM ((AP_APP LEFT JOIN AP_APP_TAG ON " + + "AP_APP.ID = AP_APP_TAG.AP_APP_ID) LEFT JOIN AP_UNRESTRICTED_ROLES ON " + + "AP_APP.ID = AP_UNRESTRICTED_ROLES.AP_APP_ID) WHERE AP_APP.TENANT_ID = ? AND AP_APP.STATUS != ?"; + + + if (filter == null) { + throw new ApplicationManagementDAOException("Filter need to be instantiated"); + } + + if (filter.getAppType() != null) { + sql += " AND AP_APP.TYPE "; + sql += "= ?"; + } + if (filter.getAppName() != null) { + sql += " AND LOWER (AP_APP.NAME) "; + if (filter.isFullMatch()) { + sql += "= ?"; + } else { + sql += "LIKE ?"; + } + } + + sql += " AND rownum <= ? OFFSET ? " + filter.getSortBy() + " APP_ID"; + + pagination.setLimit(filter.getLimit()); + pagination.setOffset(filter.getOffset()); + + try { + conn = this.getDBConnection(); + stmt = conn.prepareStatement(sql); + stmt.setInt(1, tenantId); + stmt.setString(2, AppLifecycleState.REMOVED.toString()); + + if (filter.getAppType() != null) { + stmt.setString(3, filter.getAppType()); + } + if (filter.getAppName() != null) { + if (filter.isFullMatch()) { + stmt.setString(4, filter.getAppName().toLowerCase()); + } else { + stmt.setString(4, "%" + filter.getAppName().toLowerCase() + "%"); + } + } + + stmt.setInt(5, filter.getLimit()); + stmt.setInt(6, filter.getOffset()); + rs = stmt.executeQuery(); + applicationList.setApplications(Util.loadApplications(rs)); + applicationList.setPagination(pagination); + applicationList.getPagination().setSize(filter.getOffset()); + applicationList.getPagination().setCount(applicationList.getApplications().size()); + + } catch (SQLException e) { + throw new ApplicationManagementDAOException("Error occurred while getting application list for the tenant" + + " " + tenantId + ". While executing " + sql, e); + } catch (DBConnectionException e) { + throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection while " + + "getting application list for the tenant " + tenantId, + e); + } catch (JSONException e) { + throw new ApplicationManagementDAOException("Error occurred while parsing JSON ", e); + } finally { + Util.cleanupResources(stmt, rs); + } + return applicationList; + } + +} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/release/GenericApplicationReleaseDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/release/GenericApplicationReleaseDAOImpl.java index cae5816b8b..c438c6e326 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/release/GenericApplicationReleaseDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/release/GenericApplicationReleaseDAOImpl.java @@ -182,7 +182,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements * @throws ApplicationManagementDAOException Application Management DAO Exception. */ @Override - public List getApplicationReleases(String applicationName, String applicationType, int tenantId) + public List getReleases(String applicationName, String applicationType, int tenantId) throws ApplicationManagementDAOException { Connection connection; PreparedStatement statement = null; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/release/OracleApplicationDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/release/OracleApplicationDAOImpl.java deleted file mode 100644 index 2769c5a678..0000000000 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/release/OracleApplicationDAOImpl.java +++ /dev/null @@ -1,76 +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.impl.application.release; - -import org.wso2.carbon.device.application.mgt.common.Filter; -import org.wso2.carbon.device.application.mgt.core.dao.impl.application.GenericApplicationDAOImpl; - -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.SQLException; - -/** - * This is a ApplicationDAO Implementation specific to Oracle. - */ -public class OracleApplicationDAOImpl extends GenericApplicationDAOImpl { - -// @Override -// protected PreparedStatement generateGetApplicationsStatement(Filter filter, Connection conn, -// int tenantId) throws SQLException { -// int index = 0; -// String sql = "SELECT APP.*, APL.NAME AS APL_NAME, APL.IDENTIFIER AS APL_IDENTIFIER, CAT.ID AS CAT_ID, " -// + "CAT.NAME AS CAT_NAME, LS.NAME AS LS_NAME, LS.IDENTIFIER AS LS_IDENTIFIER, " -// + "LS.DESCRIPTION AS LS_DESCRIPTION " + "FROM APPM_APPLICATION APP " + "INNER JOIN APPM_PLATFORM APL " -// + "ON APP.PLATFORM_ID = APL.ID " + "INNER JOIN APPM_APPLICATION_CATEGORY CAT " -// + "ON APP.APPLICATION_CATEGORY_ID = CAT.ID " + "INNER JOIN APPM_LIFECYCLE_STATE LS " -// + "ON APP.LIFECYCLE_STATE_ID = LS.ID WHERE APP.TENANT_ID = ? "; -// -// String userName = filter.getUserName(); -// if (!userName.equals("ALL")) { -// sql += " AND APP.CREATED_BY = ? "; -// } -// if (filter.getSearchQuery() != null && !filter.getSearchQuery().isEmpty()) { -// sql += "AND LOWER (APP.NAME) "; -// if (filter.isFullMatch()) { -// sql += "= ?"; -// } else { -// sql += "LIKE ?"; -// } -// } -// sql += " ORDER BY APP.ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; -// PreparedStatement stmt = conn.prepareStatement(sql); -// stmt.setInt(++index, tenantId); -// -// if (!userName.equals("ALL")) { -// stmt.setString(++index, userName); -// } -// if (filter.getSearchQuery() != null && !filter.getSearchQuery().isEmpty()) { -// if (filter.isFullMatch()) { -// stmt.setString(++index, filter.getSearchQuery().toLowerCase()); -// } else { -// stmt.setString(++index, "%" + filter.getSearchQuery().toLowerCase() + "%"); -// } -// } -// stmt.setInt(++index, filter.getOffset()); -// stmt.setInt(++index, filter.getLimit()); -// return stmt; -// } - -} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/lifecyclestate/GenericLifecycleStateImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/lifecyclestate/GenericLifecycleStateDAOImpl.java similarity index 97% rename from components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/lifecyclestate/GenericLifecycleStateImpl.java rename to components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/lifecyclestate/GenericLifecycleStateDAOImpl.java index 9effb6c1ed..e2a0b0198a 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/lifecyclestate/GenericLifecycleStateImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/lifecyclestate/GenericLifecycleStateDAOImpl.java @@ -36,7 +36,7 @@ import java.util.List; /** * Concrete implementation for Lifecycle related DB operations. */ -public class GenericLifecycleStateImpl extends AbstractDAOImpl implements LifecycleStateDAO { +public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements LifecycleStateDAO { @Override public LifecycleState getLatestLifeCycleStateByReleaseID(int applicationReleaseId) throws ApplicationManagementDAOException { @@ -80,13 +80,12 @@ public class GenericLifecycleStateImpl extends AbstractDAOImpl implements Lifecy Connection conn = null; PreparedStatement stmt = null; ResultSet rs = null; - int index = 0; try { conn = this.getDBConnection(); String sql = "SELECT ID, CURRENT_STATE, PREVIOUSE_STATE, TENANT_ID, UPDATED_AT, UPDATED_BY FROM " + "AP_APP_LIFECYCLE_STATE WHERE AP_APP_RELEASE_ID = ? ORDER BY UPDATED_AT ASC;"; stmt = conn.prepareStatement(sql); - stmt.setInt(++index,appReleaseId); + stmt.setInt(1,appReleaseId); rs = stmt.executeQuery(); while (rs.next()) { LifecycleState lifecycleState = new LifecycleState(); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/visibility/GenericVisibilityDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/visibility/GenericVisibilityDAOImpl.java index d5f0dadf72..0722b36a0b 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/visibility/GenericVisibilityDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/visibility/GenericVisibilityDAOImpl.java @@ -49,16 +49,15 @@ public class GenericVisibilityDAOImpl extends AbstractDAOImpl implements Visibil Connection conn; PreparedStatement stmt = null; ResultSet rs = null; - int index = 0; String sql = "INSERT INTO AP_UNRESTRICTED_ROLES (ROLE, TENANT_ID, AP_APP_ID) VALUES (?, ?, ?)"; try{ conn = this.getDBConnection(); conn.setAutoCommit(false); stmt = conn.prepareStatement(sql); for (UnrestrictedRole role : unrestrictedRoles) { - stmt.setString(++index, role.getRole()); - stmt.setInt(++index, tenantId); - stmt.setInt(++index, applicationId); + stmt.setString(1, role.getRole()); + stmt.setInt(2, tenantId); + stmt.setInt(3, applicationId); stmt.addBatch(); } stmt.executeBatch(); @@ -82,14 +81,13 @@ public class GenericVisibilityDAOImpl extends AbstractDAOImpl implements Visibil ResultSet rs = null; List unrestrictedRoles = new ArrayList<>(); UnrestrictedRole unrestrictedRole = null; - int index = 0; String sql = "SELECT ID, ROLE FROM AP_UNRESTRICTED_ROLES WHERE AP_APP_ID = ? AND TENANT_ID = ?;"; try{ conn = this.getDBConnection(); conn.setAutoCommit(false); stmt = conn.prepareStatement(sql); - stmt.setInt(++index, applicationId); - stmt.setInt(++index, tenantId); + stmt.setInt(1, applicationId); + stmt.setInt(2, tenantId); rs = stmt.executeQuery(); while (rs.next()){ @@ -117,17 +115,16 @@ public class GenericVisibilityDAOImpl extends AbstractDAOImpl implements Visibil Connection conn; PreparedStatement stmt = null; ResultSet rs = null; - int index = 0; - String sql = "DELETE FROM AP_UNRESTRICTED_ROLES WHERE AP_APP_ID = 1 AND ROLE = 'role1' AND TENANT_ID = -1234;"; + String sql = "DELETE FROM AP_UNRESTRICTED_ROLES WHERE AP_APP_ID = ? AND ROLE = ? AND TENANT_ID = ?;"; try{ conn = this.getDBConnection(); conn.setAutoCommit(false); stmt = conn.prepareStatement(sql); for (UnrestrictedRole role : unrestrictedRoles) { - stmt.setInt(++index, applicationId); - stmt.setString(++index, role.getRole()); - stmt.setInt(++index, role.getTenantId()); + stmt.setInt(1, applicationId); + stmt.setString(2, role.getRole()); + stmt.setInt(3, role.getTenantId()); stmt.addBatch(); } stmt.executeBatch(); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java index d1f5acc99e..990520e6b3 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java @@ -387,7 +387,7 @@ public class ApplicationManagerImpl implements ApplicationManager { try { ConnectionManagerUtil.openDBConnection(); applicationReleases = ApplicationManagementDAOFactory.getApplicationReleaseDAO() - .getApplicationReleases(application.getName(), application.getType(), tenantId); + .getReleases(application.getName(), application.getType(), tenantId); for (ApplicationRelease applicationRelease : applicationReleases) { if (!AppLifecycleState.REMOVED.toString().equals(ApplicationManagementDAOFactory.getLifecycleStateDAO(). getLatestLifeCycleStateByReleaseID(applicationRelease.getId()).getCurrentState())) {