|
|
@ -21,21 +21,34 @@ package org.wso2.carbon.device.application.mgt.core.dao.impl.application;
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.json.JSONException;
|
|
|
|
import org.json.JSONException;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.*;
|
|
|
|
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.ApplicationRelease;
|
|
|
|
|
|
|
|
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.Pagination;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException;
|
|
|
|
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.ApplicationDAO;
|
|
|
|
|
|
|
|
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.dao.impl.AbstractDAOImpl;
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.dao.common.Util;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.util.JSONUtil;
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.util.JSONUtil;
|
|
|
|
|
|
|
|
|
|
|
|
import java.sql.*;
|
|
|
|
import java.sql.Connection;
|
|
|
|
|
|
|
|
import java.sql.Date;
|
|
|
|
|
|
|
|
import java.sql.PreparedStatement;
|
|
|
|
|
|
|
|
import java.sql.ResultSet;
|
|
|
|
|
|
|
|
import java.sql.SQLException;
|
|
|
|
|
|
|
|
import java.sql.Statement;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* This handles ApplicationDAO related operations.
|
|
|
|
|
|
|
|
*/
|
|
|
|
public class GenericApplicationDAOImpl extends AbstractDAOImpl implements ApplicationDAO {
|
|
|
|
public class GenericApplicationDAOImpl extends AbstractDAOImpl implements ApplicationDAO {
|
|
|
|
|
|
|
|
|
|
|
|
private static final Log log = LogFactory.getLog(GenericApplicationDAOImpl.class);
|
|
|
|
private static final Log log = LogFactory.getLog(GenericApplicationDAOImpl.class);
|
|
|
@ -78,8 +91,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
|
|
|
|
stmt.setInt(14, application.getPlatform().getId());
|
|
|
|
stmt.setInt(14, application.getPlatform().getId());
|
|
|
|
stmt.setInt(15, application.getUser().getTenantId());
|
|
|
|
stmt.setInt(15, application.getUser().getTenantId());
|
|
|
|
stmt.setInt(16, application.getCurrentLifecycle().getLifecycleState().getId());
|
|
|
|
stmt.setInt(16, application.getCurrentLifecycle().getLifecycleState().getId());
|
|
|
|
stmt.setDate(17, new Date(
|
|
|
|
stmt.setDate(17, new Date(application.getCurrentLifecycle().getLifecycleStateModifiedAt().getTime()));
|
|
|
|
application.getCurrentLifecycle().getLifecycleStateModifiedAt().getTime()));
|
|
|
|
|
|
|
|
stmt.setString(18, application.getCurrentLifecycle().getGetLifecycleStateModifiedBy());
|
|
|
|
stmt.setString(18, application.getCurrentLifecycle().getGetLifecycleStateModifiedBy());
|
|
|
|
stmt.executeUpdate();
|
|
|
|
stmt.executeUpdate();
|
|
|
|
|
|
|
|
|
|
|
@ -88,6 +100,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
|
|
|
|
application.setId(rs.getInt(1));
|
|
|
|
application.setId(rs.getInt(1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
insertApplicationTagsAndProperties(application, stmt, conn, isBatchExecutionSupported);
|
|
|
|
insertApplicationTagsAndProperties(application, stmt, conn, isBatchExecutionSupported);
|
|
|
|
|
|
|
|
return application;
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e);
|
|
|
|
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e);
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
@ -95,8 +108,6 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
Util.cleanupResources(stmt, rs);
|
|
|
|
Util.cleanupResources(stmt, rs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return application;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -276,9 +287,10 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
|
|
|
|
Util.cleanupResources(null, rsProperties);
|
|
|
|
Util.cleanupResources(null, rsProperties);
|
|
|
|
Util.cleanupResources(null, rsTags);
|
|
|
|
Util.cleanupResources(null, rsTags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return application;
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new ApplicationManagementDAOException("Error occurred while getting application details with UUID "
|
|
|
|
throw new ApplicationManagementDAOException(
|
|
|
|
+ uuid, e);
|
|
|
|
"Error occurred while getting application details with UUID " + uuid, e);
|
|
|
|
} catch (JSONException e) {
|
|
|
|
} catch (JSONException e) {
|
|
|
|
throw new ApplicationManagementDAOException("Error occurred while parsing JSON", e);
|
|
|
|
throw new ApplicationManagementDAOException("Error occurred while parsing JSON", e);
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
@ -286,7 +298,6 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
Util.cleanupResources(stmt, rs);
|
|
|
|
Util.cleanupResources(stmt, rs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return application;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -361,9 +372,8 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Application editApplication(Application application, int tenantId) throws ApplicationManagementDAOException {
|
|
|
|
public Application editApplication(Application application, int tenantId) throws ApplicationManagementDAOException {
|
|
|
|
Connection conn = null;
|
|
|
|
Connection conn;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
|
|
|
|
String sql = "";
|
|
|
|
String sql = "";
|
|
|
|
boolean isBatchExecutionSupported = ConnectionManagerUtil.isBatchQuerySupported();
|
|
|
|
boolean isBatchExecutionSupported = ConnectionManagerUtil.isBatchQuerySupported();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
@ -431,13 +441,14 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
|
|
|
|
stmt.executeUpdate();
|
|
|
|
stmt.executeUpdate();
|
|
|
|
|
|
|
|
|
|
|
|
insertApplicationTagsAndProperties(application, stmt, conn, isBatchExecutionSupported);
|
|
|
|
insertApplicationTagsAndProperties(application, stmt, conn, isBatchExecutionSupported);
|
|
|
|
|
|
|
|
return application;
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e);
|
|
|
|
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e);
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new ApplicationManagementDAOException("Error occurred while adding the application", e);
|
|
|
|
throw new ApplicationManagementDAOException("Error occurred while adding the application", e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
Util.cleanupResources(stmt, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return application;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -509,7 +520,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void deleteProperties(int applicationId) throws ApplicationManagementDAOException {
|
|
|
|
public void deleteProperties(int applicationId) throws ApplicationManagementDAOException {
|
|
|
|
Connection conn = null;
|
|
|
|
Connection conn;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getDBConnection();
|
|
|
|
conn = this.getDBConnection();
|
|
|
@ -530,10 +541,8 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void deleteTags(int applicationId) throws ApplicationManagementDAOException {
|
|
|
|
public void deleteTags(int applicationId) throws ApplicationManagementDAOException {
|
|
|
|
|
|
|
|
Connection conn;
|
|
|
|
Connection conn = null;
|
|
|
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getDBConnection();
|
|
|
|
conn = this.getDBConnection();
|
|
|
|
String sql = "DELETE FROM APPM_APPLICATION_TAG WHERE APPLICATION_ID = ?";
|
|
|
|
String sql = "DELETE FROM APPM_APPLICATION_TAG WHERE APPLICATION_ID = ?";
|
|
|
@ -547,7 +556,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
|
|
|
|
throw new ApplicationManagementDAOException(
|
|
|
|
throw new ApplicationManagementDAOException(
|
|
|
|
"Error occurred while deleting tags of application: " + applicationId, e);
|
|
|
|
"Error occurred while deleting tags of application: " + applicationId, e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
Util.cleanupResources(stmt, rs);
|
|
|
|
Util.cleanupResources(stmt, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -556,13 +565,11 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
|
|
|
|
Connection conn = null;
|
|
|
|
Connection conn = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
String sql = "";
|
|
|
|
String sql;
|
|
|
|
|
|
|
|
|
|
|
|
int id = 0;
|
|
|
|
int id = 0;
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getDBConnection();
|
|
|
|
conn = this.getDBConnection();
|
|
|
|
sql += "SELECT ID FROM APPM_APPLICATION WHERE UUID = ?";
|
|
|
|
sql = "SELECT ID FROM APPM_APPLICATION WHERE UUID = ?";
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt.setString(1, uuid);
|
|
|
|
stmt.setString(1, uuid);
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
rs = stmt.executeQuery();
|
|
|
@ -576,7 +583,6 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
Util.cleanupResources(stmt, rs);
|
|
|
|
Util.cleanupResources(stmt, rs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return id;
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|