use of org.wso2.carbon.identity.configuration.mgt.core.search.PlaceholderSQL in project carbon-identity-framework by wso2.
the class ConfigurationDAOImpl method getTenantResources.
/**
* {@inheritDoc}
*/
@Override
public Resources getTenantResources(Condition condition) throws ConfigurationManagementException {
PlaceholderSQL placeholderSQL = buildPlaceholderSQL(condition, useCreatedTimeField());
if (placeholderSQL.getQuery().getBytes().length > getMaximumQueryLengthInBytes()) {
if (log.isDebugEnabled()) {
log.debug("Error building SQL query for the search. Search expression " + "query length: " + placeholderSQL.getQuery().length() + " exceeds the maximum limit: " + MAX_QUERY_LENGTH_IN_BYTES_SQL);
}
throw handleClientException(ERROR_CODE_QUERY_LENGTH_EXCEEDED, null);
}
JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();
List<ConfigurationRawDataCollector> configurationRawDataCollectors;
try {
configurationRawDataCollectors = jdbcTemplate.executeQuery(placeholderSQL.getQuery(), (resultSet, rowNumber) -> {
ConfigurationRawDataCollector.ConfigurationRawDataCollectorBuilder configurationRawDataCollectorBuilder = new ConfigurationRawDataCollector.ConfigurationRawDataCollectorBuilder().setResourceId(resultSet.getString(DB_SCHEMA_COLUMN_NAME_ID)).setTenantId(resultSet.getInt(DB_SCHEMA_COLUMN_NAME_TENANT_ID)).setResourceName(resultSet.getString(DB_SCHEMA_COLUMN_NAME_NAME)).setLastModified(resultSet.getTimestamp(DB_SCHEMA_COLUMN_NAME_LAST_MODIFIED, calendar)).setResourceTypeName(resultSet.getString(DB_SCHEMA_COLUMN_NAME_RESOURCE_TYPE)).setResourceTypeDescription(resultSet.getString(DB_SCHEMA_COLUMN_NAME_DESCRIPTTION)).setAttributeKey(resultSet.getString(DB_SCHEMA_COLUMN_NAME_ATTRIBUTE_KEY)).setAttributeValue(resultSet.getString(DB_SCHEMA_COLUMN_NAME_ATTRIBUTE_VALUE)).setAttributeId(resultSet.getString(DB_SCHEMA_COLUMN_NAME_ATTRIBUTE_ID)).setFileId(resultSet.getString(DB_SCHEMA_COLUMN_NAME_FILE_ID));
if (useCreatedTimeField()) {
configurationRawDataCollectorBuilder.setCreatedTime(resultSet.getTimestamp(DB_SCHEMA_COLUMN_NAME_CREATED_TIME, calendar));
}
return configurationRawDataCollectorBuilder.build();
}, preparedStatement -> {
for (int count = 0; count < placeholderSQL.getData().size(); count++) {
if (placeholderSQL.getData().get(count).getClass().equals(Integer.class)) {
preparedStatement.setInt(count + 1, (Integer) placeholderSQL.getData().get(count));
} else {
preparedStatement.setString(count + 1, (String) placeholderSQL.getData().get(count));
}
}
});
/*
Database call can contain duplicate data for some columns. Need to filter them in order to build the
resource.
*/
return configurationRawDataCollectors == null || configurationRawDataCollectors.size() == 0 ? null : buildResourcesFromRawData(configurationRawDataCollectors);
} catch (DataAccessException e) {
throw handleServerException(ERROR_CODE_SEARCH_TENANT_RESOURCES, null, e);
}
}
use of org.wso2.carbon.identity.configuration.mgt.core.search.PlaceholderSQL in project carbon-identity-framework by wso2.
the class ConfigurationDAOImpl method buildPlaceholderSQL.
private PlaceholderSQL buildPlaceholderSQL(Condition condition, boolean useCreatedTime) throws ConfigurationManagementException {
String queryWithCreatedTime = GET_TENANT_RESOURCES_SELECT_COLUMNS_MYSQL;
String queryWithOutCreatedTime = GET_TENANT_RESOURCES_SELECT_COLUMNS_MYSQL_WITHOUT_CREATED_TIME;
try {
if (isOracleDB() || isMSSqlDB()) {
queryWithCreatedTime = GET_TENANT_RESOURCES_SELECT_COLUMNS_MSSQL_OR_ORACLE;
}
} catch (DataAccessException e) {
throw handleServerException(ERROR_CODE_CHECK_DB_METADATA, e.getMessage(), e);
}
StringBuilder sb = new StringBuilder();
sb.append(useCreatedTime ? queryWithCreatedTime : queryWithOutCreatedTime);
sb.append("WHERE\n");
try {
PlaceholderSQL placeholderSQL = condition.buildQuery(new PrimitiveConditionValidator(new ResourceSearchBean()));
placeholderSQL.setQuery(sb.append(placeholderSQL.getQuery()).toString());
return placeholderSQL;
} catch (PrimitiveConditionValidationException e) {
throw handleClientException(ERROR_CODE_SEARCH_QUERY_SQL_PROPERTY_PARSE_ERROR, e.getMessage(), e);
}
}
Aggregations