use of org.wso2.carbon.idp.mgt.util.IdPManagementConstants.MySQL in project carbon-apimgt by wso2.
the class MysqlSQLStatements method prepareAttributeSearchStatementForStore.
/**
* @see ApiDAOVendorSpecificStatements#prepareAttributeSearchStatementForStore(Connection connection, List, List,
* Map, int, int)
*/
@Override
@SuppressFBWarnings({ "SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING", "OBL_UNSATISFIED_OBLIGATION_EXCEPTION_EDGE" })
public PreparedStatement prepareAttributeSearchStatementForStore(Connection connection, List<String> roles, List<String> labels, Map<String, String> attributeMap, int offset, int limit) throws APIMgtDAOException {
StringBuilder roleListBuilder = new StringBuilder();
roleListBuilder.append("?");
for (int i = 0; i < roles.size() - 1; i++) {
roleListBuilder.append(",?");
}
StringBuilder searchQuery = new StringBuilder();
Iterator<Map.Entry<String, String>> entries = attributeMap.entrySet().iterator();
while (entries.hasNext()) {
Map.Entry<String, String> entry = entries.next();
searchQuery.append("LOWER(");
if (APIMgtConstants.TAG_SEARCH_TYPE_PREFIX.equalsIgnoreCase(entry.getKey())) {
searchQuery.append(APIMgtConstants.TAG_NAME_COLUMN);
} else if (APIMgtConstants.SUBCONTEXT_SEARCH_TYPE_PREFIX.equalsIgnoreCase(entry.getKey())) {
searchQuery.append(APIMgtConstants.URL_PATTERN_COLUMN);
} else {
searchQuery.append(entry.getKey());
}
searchQuery.append(") LIKE ?");
if (entries.hasNext()) {
searchQuery.append(" AND ");
}
}
// retrieve the attribute applicable for the search
String searchAttribute = attributeMap.entrySet().iterator().next().getKey();
// get the corresponding implementation based on the attribute to be searched
String query = searchMap.get(searchAttribute).getStoreAttributeSearchQuery(roleListBuilder, searchQuery, offset, limit);
query = "Select * from ( " + query + " ) A" + getStoreAPIsByLabelJoinQuery(labels);
try {
int queryIndex = 1;
PreparedStatement statement = connection.prepareStatement(query);
// include the attribute in the query (for APIs with public visibility)
for (Map.Entry<String, String> entry : attributeMap.entrySet()) {
statement.setString(queryIndex, '%' + entry.getValue().toLowerCase(Locale.ENGLISH) + '%');
queryIndex++;
}
// include user roles in the query
for (String role : roles) {
statement.setString(queryIndex, role);
queryIndex++;
}
// include the attribute in the query (for APIs with restricted visibility)
for (Map.Entry<String, String> entry : attributeMap.entrySet()) {
statement.setString(queryIndex, '%' + entry.getValue().toLowerCase(Locale.ENGLISH) + '%');
queryIndex++;
}
for (String label : labels) {
statement.setString(queryIndex, label);
queryIndex++;
}
// setting 0 as the default offset based on store-api.yaml and MySQL specifications
statement.setInt(queryIndex, (offset < 0) ? 0 : offset);
statement.setInt(++queryIndex, limit);
return statement;
} catch (SQLException e) {
String errorMsg = "Error occurred while searching APIs for attributes in the database.";
log.error(errorMsg, e);
throw new APIMgtDAOException(errorMsg, e);
}
}
use of org.wso2.carbon.idp.mgt.util.IdPManagementConstants.MySQL in project carbon-apimgt by wso2.
the class DAOFactory method getWorkflowDAO.
public static WorkflowDAO getWorkflowDAO() throws APIMgtDAOException {
WorkflowDAO workflowDAO = null;
try (Connection connection = DAOUtil.getConnection()) {
String driverName = connection.getMetaData().getDriverName();
if (driverName.contains(MYSQL) || driverName.contains(H2)) {
workflowDAO = new WorkflowDAOImpl();
} else if (driverName.contains(DB2)) {
} else if (driverName.contains(MS_SQL) || driverName.contains(MICROSOFT)) {
workflowDAO = new WorkflowDAOImpl();
} else if (driverName.contains(POSTGRE)) {
workflowDAO = new WorkflowDAOImpl();
} else if (driverName.contains(ORACLE)) {
workflowDAO = new WorkflowDAOImpl();
} else {
throw new APIMgtDAOException("Unhandled DB driver: " + driverName + " detected", ExceptionCodes.APIM_DAO_EXCEPTION);
}
} catch (SQLException e) {
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "getting WorkflowDAO", e);
}
setup();
return workflowDAO;
}
use of org.wso2.carbon.idp.mgt.util.IdPManagementConstants.MySQL in project carbon-apimgt by wso2.
the class DAOFactory method getApplicationDAO.
public static ApplicationDAO getApplicationDAO() throws APIMgtDAOException {
ApplicationDAO appDAO = null;
try (Connection connection = DAOUtil.getConnection()) {
String driverName = connection.getMetaData().getDriverName();
if (driverName.contains(MYSQL) || driverName.contains(H2)) {
appDAO = new ApplicationDAOImpl();
} else if (driverName.contains(DB2)) {
} else if (driverName.contains(MS_SQL) || driverName.contains(MICROSOFT)) {
appDAO = new ApplicationDAOImpl();
} else if (driverName.contains(POSTGRE)) {
appDAO = new ApplicationDAOImpl();
} else if (driverName.contains(ORACLE)) {
appDAO = new ApplicationDAOImpl();
} else {
throw new APIMgtDAOException("Unhandled DB driver: " + driverName + " detected", ExceptionCodes.APIM_DAO_EXCEPTION);
}
} catch (SQLException e) {
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "getting ApplicationDAO", e);
}
setup();
return appDAO;
}
use of org.wso2.carbon.idp.mgt.util.IdPManagementConstants.MySQL in project carbon-apimgt by wso2.
the class DAOFactory method getLabelDAO.
public static LabelDAO getLabelDAO() throws APIMgtDAOException {
LabelDAO labelDAO = null;
try (Connection connection = DAOUtil.getConnection()) {
String driverName = connection.getMetaData().getDriverName();
if (driverName.contains(MYSQL) || driverName.contains(H2)) {
labelDAO = new LabelDAOImpl();
} else if (driverName.contains(DB2)) {
} else if (driverName.contains(MS_SQL) || driverName.contains(MICROSOFT)) {
labelDAO = new LabelDAOImpl();
} else if (driverName.contains(POSTGRE)) {
labelDAO = new LabelDAOImpl();
} else if (driverName.contains(ORACLE)) {
labelDAO = new LabelDAOImpl();
} else {
throw new APIMgtDAOException("Unhandled DB driver: " + driverName + " detected", ExceptionCodes.APIM_DAO_EXCEPTION);
}
} catch (SQLException e) {
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "getting LabelDAO", e);
}
setup();
return labelDAO;
}
use of org.wso2.carbon.idp.mgt.util.IdPManagementConstants.MySQL in project carbon-identity-framework by wso2.
the class ApplicationDAOImpl method getApplicationBasicInfo.
@Override
public ApplicationBasicInfo[] getApplicationBasicInfo(String filter, int offset, int limit) throws IdentityApplicationManagementException {
validateAttributesForPagination(offset, limit);
if ("*".equals(filter)) {
return getApplicationBasicInfo(offset, limit);
}
validateAttributesForPagination(offset, limit);
int tenantID = CarbonContext.getThreadLocalCarbonContext().getTenantId();
Connection connection = IdentityDatabaseUtil.getDBConnection(false);
PreparedStatement getAppNamesStmt = null;
ResultSet appNameResultSet = null;
String sqlQuery;
ArrayList<ApplicationBasicInfo> appInfo = new ArrayList<>();
try {
String filterResolvedForSQL = resolveSQLFilter(filter);
String databaseProductName = connection.getMetaData().getDatabaseProductName();
if (databaseProductName.contains("MySQL") || databaseProductName.contains("MariaDB") || databaseProductName.contains("H2")) {
sqlQuery = LOAD_APP_NAMES_BY_TENANT_AND_APP_NAME_MYSQL;
getAppNamesStmt = connection.prepareStatement(sqlQuery);
populateApplicationSearchQuery(getAppNamesStmt, tenantID, filterResolvedForSQL, offset, limit);
} else if (databaseProductName.contains("Oracle")) {
sqlQuery = LOAD_APP_NAMES_BY_TENANT_AND_APP_NAME_ORACLE;
getAppNamesStmt = connection.prepareStatement(sqlQuery);
populateApplicationSearchQuery(getAppNamesStmt, tenantID, filterResolvedForSQL, offset + limit, offset);
} else if (databaseProductName.contains("Microsoft")) {
sqlQuery = LOAD_APP_NAMES_BY_TENANT_AND_APP_NAME_MSSQL;
getAppNamesStmt = connection.prepareStatement(sqlQuery);
populateApplicationSearchQuery(getAppNamesStmt, tenantID, filterResolvedForSQL, offset, limit);
} else if (databaseProductName.contains("PostgreSQL")) {
sqlQuery = LOAD_APP_NAMES_BY_TENANT_AND_APP_NAME_POSTGRESQL;
getAppNamesStmt = connection.prepareStatement(sqlQuery);
populateApplicationSearchQuery(getAppNamesStmt, tenantID, filterResolvedForSQL, limit, offset);
} else if (databaseProductName.contains("DB2")) {
sqlQuery = LOAD_APP_NAMES_BY_TENANT_AND_APP_NAME_DB2SQL;
getAppNamesStmt = connection.prepareStatement(sqlQuery);
populateApplicationSearchQuery(getAppNamesStmt, tenantID, filterResolvedForSQL, offset + 1, offset + limit);
} else if (databaseProductName.contains("INFORMIX")) {
sqlQuery = LOAD_APP_NAMES_BY_TENANT_AND_APP_NAME_INFORMIX;
getAppNamesStmt = connection.prepareStatement(sqlQuery);
getAppNamesStmt.setInt(1, offset);
getAppNamesStmt.setInt(2, limit);
getAppNamesStmt.setInt(3, tenantID);
getAppNamesStmt.setString(4, filterResolvedForSQL);
getAppNamesStmt.setString(5, LOCAL_SP);
} else {
log.error("Error while loading applications from DB: Database driver could not be identified or " + "not supported.");
throw new IdentityApplicationManagementException("Error while loading applications from DB:" + "Database driver could not be identified or not supported.");
}
appNameResultSet = getAppNamesStmt.executeQuery();
while (appNameResultSet.next()) {
appInfo.add(buildApplicationBasicInfo(appNameResultSet));
}
} catch (SQLException e) {
throw new IdentityApplicationManagementException("Error while loading applications from DB: " + e.getMessage(), e);
} finally {
IdentityApplicationManagementUtil.closeStatement(getAppNamesStmt);
IdentityApplicationManagementUtil.closeResultSet(appNameResultSet);
IdentityApplicationManagementUtil.closeConnection(connection);
}
return appInfo.toArray(new ApplicationBasicInfo[0]);
}
Aggregations