use of org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException 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);
}
}
use of org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException in project carbon-identity-framework by wso2.
the class ConfigurationDAOImpl method deleteResourceByName.
/**
* {@inheritDoc}
*/
@Override
public void deleteResourceByName(int tenantId, String resourceTypeId, String resourceName) throws ConfigurationManagementException {
JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();
try {
if (isMySQLDB()) {
String resourceId = getResourceId(tenantId, resourceTypeId, resourceName);
deleteFiles(resourceId);
}
jdbcTemplate.executeUpdate(SQLConstants.DELETE_RESOURCE_SQL, preparedStatement -> {
int initialParameterIndex = 1;
preparedStatement.setString(initialParameterIndex, resourceName);
preparedStatement.setInt(++initialParameterIndex, tenantId);
preparedStatement.setString(++initialParameterIndex, resourceTypeId);
});
} catch (DataAccessException | TransactionException e) {
throw handleServerException(ERROR_CODE_DELETE_RESOURCE_TYPE, resourceName, e);
}
}
use of org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException in project carbon-identity-framework by wso2.
the class ConfigurationDAOImpl method deleteFiles.
@Override
public void deleteFiles(String resourceId) throws ConfigurationManagementException {
JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();
try {
boolean isOracleOrMssql = isOracleDB() || isMSSqlDB();
jdbcTemplate.withTransaction(template -> {
template.executeUpdate(DELETE_FILES_SQL, (preparedStatement -> preparedStatement.setString(1, resourceId)));
template.executeUpdate(UPDATE_HAS_FILE_SQL, preparedStatement -> {
if (isOracleOrMssql) {
preparedStatement.setInt(1, 0);
} else {
preparedStatement.setBoolean(1, false);
}
preparedStatement.setString(2, resourceId);
});
updateResourceLastModified(template, resourceId);
return null;
});
} catch (TransactionException e) {
throw handleServerException(ERROR_CODE_DELETE_FILES, resourceId, e);
} catch (DataAccessException e) {
throw handleServerException(ERROR_CODE_CHECK_DB_METADATA, e.getMessage(), e);
}
}
use of org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException in project carbon-identity-framework by wso2.
the class ConfigurationDAOImpl method isExistingResource.
@Override
public boolean isExistingResource(int tenantId, String resourceId) throws ConfigurationManagementException {
JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();
String resourceName;
try {
resourceName = jdbcTemplate.fetchSingleRecord(GET_RESOURCE_NAME_BY_ID, (resultSet, rowNumber) -> resultSet.getString(DB_SCHEMA_COLUMN_NAME_NAME), preparedStatement -> {
preparedStatement.setString(1, resourceId);
preparedStatement.setInt(2, tenantId);
});
return StringUtils.isNotEmpty(resourceName);
} catch (DataAccessException e) {
throw handleServerException(ERROR_CODE_GET_RESOURCE, "id = " + resourceId, e);
}
}
use of org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException in project carbon-identity-framework by wso2.
the class SecretDAOImpl method getSecretByName.
@Override
public Secret getSecretByName(String name, SecretType secretType, int tenantId) throws SecretManagementException {
NamedJdbcTemplate jdbcTemplate = getNewTemplate();
List<SecretRawDataCollector> secretRawDataCollectors;
try {
String query = GET_SECRET_BY_NAME;
secretRawDataCollectors = jdbcTemplate.executeQuery(query, (resultSet, rowNumber) -> {
SecretRawDataCollector.SecretRawDataCollectorBuilder secretRawDataCollectorBuilder = new SecretRawDataCollector.SecretRawDataCollectorBuilder().setSecretId(resultSet.getString(DB_SCHEMA_COLUMN_NAME_ID)).setTenantId(resultSet.getInt(DB_SCHEMA_COLUMN_NAME_TENANT_ID)).setSecretName(resultSet.getString(DB_SCHEMA_COLUMN_NAME_SECRET_NAME)).setSecretValue(resultSet.getString(DB_SCHEMA_COLUMN_NAME_SECRET_VALUE)).setLastModified(resultSet.getTimestamp(DB_SCHEMA_COLUMN_NAME_LAST_MODIFIED, calendar)).setCreatedTime(resultSet.getTimestamp(DB_SCHEMA_COLUMN_NAME_CREATED_TIME, calendar)).setDescription(resultSet.getString(DB_SCHEMA_COLUMN_NAME_DESCRIPTION)).setSecretType(secretType.getName());
return secretRawDataCollectorBuilder.build();
}, preparedStatement -> {
preparedStatement.setString(DB_SCHEMA_COLUMN_NAME_SECRET_NAME, name);
preparedStatement.setString(DB_SCHEMA_COLUMN_NAME_TYPE, secretType.getId());
preparedStatement.setInt(DB_SCHEMA_COLUMN_NAME_TENANT_ID, tenantId);
});
return secretRawDataCollectors == null || secretRawDataCollectors.size() == 0 ? null : buildSecretFromRawData(secretRawDataCollectors);
} catch (DataAccessException | CryptoException e) {
throw handleServerException(ERROR_CODE_GET_SECRET, name, e);
}
}
Aggregations