Search in sources :

Example 1 with ERROR_CODE_CHECK_DB_METADATA

use of org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_CHECK_DB_METADATA in project carbon-identity-framework by wso2.

the class ConfigurationDAOImpl method updateMetadataForH2.

private void updateMetadataForH2(Resource resource, String resourceTypeId, boolean isAttributeExists, Timestamp currentTime, boolean useCreatedTime) throws TransactionException, ConfigurationManagementServerException {
    JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();
    if (isResourceExists(resource, resourceTypeId)) {
        jdbcTemplate.withTransaction(template -> template.executeInsert(UPDATE_RESOURCE_H2, preparedStatement -> {
            int initialParameterIndex = 1;
            preparedStatement.setInt(initialParameterIndex, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
            preparedStatement.setString(++initialParameterIndex, resource.getResourceName());
            preparedStatement.setTimestamp(++initialParameterIndex, currentTime, calendar);
            /*
                                Resource files are uploaded using a separate endpoint. Therefore resource creation
                                does not create files. It is allowed to create a resource without files or attributes
                                in order to allow file uploadafter resource creation.
                                */
            preparedStatement.setBoolean(++initialParameterIndex, false);
            preparedStatement.setBoolean(++initialParameterIndex, isAttributeExists);
            preparedStatement.setString(++initialParameterIndex, resourceTypeId);
            preparedStatement.setString(++initialParameterIndex, resource.getResourceId());
        }, resource, false));
    } else {
        try {
            boolean isOracleOrMsssql = isOracleDB() || isMSSqlDB();
            jdbcTemplate.withTransaction(template -> template.executeInsert(useCreatedTime ? INSERT_RESOURCE_SQL : INSERT_RESOURCE_SQL_WITHOUT_CREATED_TIME, preparedStatement -> {
                int initialParameterIndex = 1;
                preparedStatement.setString(initialParameterIndex, resource.getResourceId());
                preparedStatement.setInt(++initialParameterIndex, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
                preparedStatement.setString(++initialParameterIndex, resource.getResourceName());
                if (useCreatedTime) {
                    preparedStatement.setTimestamp(++initialParameterIndex, currentTime, calendar);
                }
                preparedStatement.setTimestamp(++initialParameterIndex, currentTime, calendar);
                if (isOracleOrMsssql) {
                    preparedStatement.setInt(++initialParameterIndex, 0);
                    preparedStatement.setInt(++initialParameterIndex, isAttributeExists ? 1 : 0);
                } else {
                    preparedStatement.setBoolean(++initialParameterIndex, false);
                    preparedStatement.setBoolean(++initialParameterIndex, isAttributeExists);
                }
                preparedStatement.setString(++initialParameterIndex, resourceTypeId);
            }, resource, false));
        } catch (DataAccessException e) {
            throw handleServerException(ERROR_CODE_CHECK_DB_METADATA, e.getMessage(), e);
        }
    }
}
Also used : INSERT_OR_UPDATE_RESOURCE_POSTGRESQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_OR_UPDATE_RESOURCE_POSTGRESQL) MAX_QUERY_LENGTH_IN_BYTES_SQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.MAX_QUERY_LENGTH_IN_BYTES_SQL) DELETE_FILES_SQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.DELETE_FILES_SQL) StringUtils(org.apache.commons.lang.StringUtils) DB_SCHEMA_COLUMN_NAME_LAST_MODIFIED(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.DB_SCHEMA_COLUMN_NAME_LAST_MODIFIED) ResourceType(org.wso2.carbon.identity.configuration.mgt.core.model.ResourceType) INSERT_OR_UPDATE_ATTRIBUTE_MYSQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_OR_UPDATE_ATTRIBUTE_MYSQL) DB_SCHEMA_COLUMN_NAME_HAS_ATTRIBUTE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.DB_SCHEMA_COLUMN_NAME_HAS_ATTRIBUTE) DB_SCHEMA_COLUMN_NAME_CREATED_TIME(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.DB_SCHEMA_COLUMN_NAME_CREATED_TIME) ConfigurationManagementException(org.wso2.carbon.identity.configuration.mgt.core.exception.ConfigurationManagementException) INSERT_RESOURCE_SQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_RESOURCE_SQL) ERROR_CODE_INSERT_FILE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_INSERT_FILE) ERROR_CODE_GET_FILE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_GET_FILE) Map(java.util.Map) Condition(org.wso2.carbon.identity.configuration.mgt.core.search.Condition) ERROR_CODE_REPLACE_ATTRIBUTE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_REPLACE_ATTRIBUTE) ERROR_CODE_RESOURCE_ALREADY_EXISTS(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_RESOURCE_ALREADY_EXISTS) INSERT_OR_UPDATE_RESOURCE_MSSQL_OR_DB2(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_OR_UPDATE_RESOURCE_MSSQL_OR_DB2) INSERT_OR_UPDATE_ATTRIBUTES_POSTGRESQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_OR_UPDATE_ATTRIBUTES_POSTGRESQL) DB_SCHEMA_COLUMN_NAME_ATTRIBUTE_VALUE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.DB_SCHEMA_COLUMN_NAME_ATTRIBUTE_VALUE) INSERT_OR_UPDATE_ATTRIBUTES_MSSQL_OR_DB2(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_OR_UPDATE_ATTRIBUTES_MSSQL_OR_DB2) LambdaExceptionUtils(org.wso2.carbon.identity.core.util.LambdaExceptionUtils) ConfigurationUtils.getMaximumQueryLengthInBytes(org.wso2.carbon.identity.configuration.mgt.core.util.ConfigurationUtils.getMaximumQueryLengthInBytes) Set(java.util.Set) GET_RESOURCE_BY_ID_MYSQL_WITHOUT_CREATED_TIME(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.GET_RESOURCE_BY_ID_MYSQL_WITHOUT_CREATED_TIME) PreparedStatement(java.sql.PreparedStatement) SQLConstants(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants) JdbcUtils.isOracleDB(org.wso2.carbon.identity.core.util.JdbcUtils.isOracleDB) ERROR_CODE_UPDATE_ATTRIBUTE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_UPDATE_ATTRIBUTE) ConfigurationManagementClientException(org.wso2.carbon.identity.configuration.mgt.core.exception.ConfigurationManagementClientException) INSERT_OR_UPDATE_ATTRIBUTE_MSSQL_OR_DB2(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_OR_UPDATE_ATTRIBUTE_MSSQL_OR_DB2) GET_RESOURCE_TYPE_ID_BY_NAME_SQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.GET_RESOURCE_TYPE_ID_BY_NAME_SQL) LogFactory(org.apache.commons.logging.LogFactory) ERROR_CODE_INSERT_ATTRIBUTE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_INSERT_ATTRIBUTE) ERROR_CODE_DELETE_FILE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_DELETE_FILE) ERROR_CODE_SEARCH_QUERY_SQL_PROPERTY_PARSE_ERROR(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_SEARCH_QUERY_SQL_PROPERTY_PARSE_ERROR) GET_FILES_BY_RESOURCE_TYPE_ID_SQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.GET_FILES_BY_RESOURCE_TYPE_ID_SQL) JdbcTemplate(org.wso2.carbon.database.utils.jdbc.JdbcTemplate) ERROR_CODE_ADD_RESOURCE_TYPE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_ADD_RESOURCE_TYPE) ERROR_CODE_ADD_RESOURCE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_ADD_RESOURCE) ResourceFile(org.wso2.carbon.identity.configuration.mgt.core.model.ResourceFile) SQLIntegrityConstraintViolationException(java.sql.SQLIntegrityConstraintViolationException) INSERT_OR_UPDATE_RESOURCE_ORACLE(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_OR_UPDATE_RESOURCE_ORACLE) INSERT_OR_UPDATE_RESOURCE_TYPE_H2(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_OR_UPDATE_RESOURCE_TYPE_H2) ArrayList(java.util.ArrayList) SQLException(java.sql.SQLException) Calendar(java.util.Calendar) INSERT_OR_UPDATE_RESOURCE_TYPE_MSSQL_OR_DB2(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_OR_UPDATE_RESOURCE_TYPE_MSSQL_OR_DB2) DB_SCHEMA_COLUMN_NAME_RESOURCE_TYPE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.DB_SCHEMA_COLUMN_NAME_RESOURCE_TYPE) IdentityTenantUtil(org.wso2.carbon.identity.core.util.IdentityTenantUtil) ERROR_CODE_QUERY_LENGTH_EXCEEDED(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_QUERY_LENGTH_EXCEEDED) DB_SCHEMA_COLUMN_NAME_DESCRIPTTION(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.DB_SCHEMA_COLUMN_NAME_DESCRIPTTION) INSERT_OR_UPDATE_ATTRIBUTE_H2(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_OR_UPDATE_ATTRIBUTE_H2) GET_TENANT_RESOURCES_SELECT_COLUMNS_MSSQL_OR_ORACLE(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.GET_TENANT_RESOURCES_SELECT_COLUMNS_MSSQL_OR_ORACLE) UPDATE_HAS_FILE_SQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.UPDATE_HAS_FILE_SQL) JdbcUtils.isMSSqlDB(org.wso2.carbon.identity.core.util.JdbcUtils.isMSSqlDB) DB_SCHEMA_COLUMN_NAME_ATTRIBUTE_ID(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.DB_SCHEMA_COLUMN_NAME_ATTRIBUTE_ID) ERROR_CODE_DELETE_RESOURCE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_DELETE_RESOURCE) ERROR_CODE_REPLACE_RESOURCE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_REPLACE_RESOURCE) GET_RESOURCE_CREATED_TIME_BY_NAME_SQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.GET_RESOURCE_CREATED_TIME_BY_NAME_SQL) GET_RESOURCE_BY_ID_MSSQL_OR_ORACLE(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.GET_RESOURCE_BY_ID_MSSQL_OR_ORACLE) DB_SCHEMA_COLUMN_NAME_HAS_FILE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.DB_SCHEMA_COLUMN_NAME_HAS_FILE) GET_FILES_BY_RESOURCE_ID_SQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.GET_FILES_BY_RESOURCE_ID_SQL) ERROR_CODE_DELETE_ATTRIBUTE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_DELETE_ATTRIBUTE) ERROR_CODE_CHECK_DB_METADATA(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_CHECK_DB_METADATA) GET_RESOURCE_BY_NAME_MSSQL_OR_ORACLE(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.GET_RESOURCE_BY_NAME_MSSQL_OR_ORACLE) ERROR_CODE_UPDATE_RESOURCE_TYPE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_UPDATE_RESOURCE_TYPE) Resources(org.wso2.carbon.identity.configuration.mgt.core.model.Resources) DB_SCHEMA_COLUMN_NAME_ID(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.DB_SCHEMA_COLUMN_NAME_ID) UPDATE_RESOURCE_H2(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.UPDATE_RESOURCE_H2) INSERT_OR_UPDATE_ATTRIBUTES_MYSQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_OR_UPDATE_ATTRIBUTES_MYSQL) ConfigurationUtils.handleClientException(org.wso2.carbon.identity.configuration.mgt.core.util.ConfigurationUtils.handleClientException) DB_SCHEMA_COLUMN_NAME_RESOURCE_NAME(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.DB_SCHEMA_COLUMN_NAME_RESOURCE_NAME) Date(java.util.Date) Template(org.wso2.carbon.database.utils.jdbc.Template) DB_SCHEMA_COLUMN_NAME_FILE_NAME(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.DB_SCHEMA_COLUMN_NAME_FILE_NAME) ERROR_CODE_GET_ATTRIBUTE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_GET_ATTRIBUTE) DB_SCHEMA_COLUMN_NAME_RESOURCE_TYPE_NAME(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.DB_SCHEMA_COLUMN_NAME_RESOURCE_TYPE_NAME) GET_RESOURCE_NAME_BY_ID(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.GET_RESOURCE_NAME_BY_ID) DB_SCHEMA_COLUMN_NAME_VALUE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.DB_SCHEMA_COLUMN_NAME_VALUE) Resource(org.wso2.carbon.identity.configuration.mgt.core.model.Resource) ERROR_CODE_RESOURCES_DOES_NOT_EXISTS(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_RESOURCES_DOES_NOT_EXISTS) GET_RESOURCES_BY_RESOURCE_TYPE_ID_SQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.GET_RESOURCES_BY_RESOURCE_TYPE_ID_SQL) DB_SCHEMA_COLUMN_NAME_FILE_ID(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.DB_SCHEMA_COLUMN_NAME_FILE_ID) INSERT_OR_UPDATE_ATTRIBUTE_ORACLE(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_OR_UPDATE_ATTRIBUTE_ORACLE) ERROR_CODE_GET_FILES(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_GET_FILES) TimeZone(java.util.TimeZone) Timestamp(java.sql.Timestamp) PrimitiveConditionValidator(org.wso2.carbon.identity.configuration.mgt.core.search.PrimitiveConditionValidator) DELETE_ATTRIBUTE_SQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.DELETE_ATTRIBUTE_SQL) ERROR_CODE_RETRIEVE_RESOURCE_TYPE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_RETRIEVE_RESOURCE_TYPE) JdbcUtils.isMariaDB(org.wso2.carbon.identity.core.util.JdbcUtils.isMariaDB) ERROR_CODE_DELETE_FILES(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_DELETE_FILES) INSERT_OR_UPDATE_ATTRIBUTE_POSTGRESQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_OR_UPDATE_ATTRIBUTE_POSTGRESQL) ConfigurationManagementServerException(org.wso2.carbon.identity.configuration.mgt.core.exception.ConfigurationManagementServerException) List(java.util.List) DELETE_RESOURCE_ATTRIBUTES_SQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.DELETE_RESOURCE_ATTRIBUTES_SQL) JdbcUtils.isH2DB(org.wso2.carbon.identity.core.util.JdbcUtils.isH2DB) ConfigurationUtils.handleServerException(org.wso2.carbon.identity.configuration.mgt.core.util.ConfigurationUtils.handleServerException) DataAccessException(org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException) UTC(java.time.ZoneOffset.UTC) GET_TENANT_RESOURCES_SELECT_COLUMNS_MYSQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.GET_TENANT_RESOURCES_SELECT_COLUMNS_MYSQL) GET_RESOURCE_ID_TENANT_ID_BY_TYPE_ID_SQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.GET_RESOURCE_ID_TENANT_ID_BY_TYPE_ID_SQL) ERROR_CODE_GET_FILES_BY_TYPE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_GET_FILES_BY_TYPE) PrivilegedCarbonContext(org.wso2.carbon.context.PrivilegedCarbonContext) HashMap(java.util.HashMap) ConfigurationDAO(org.wso2.carbon.identity.configuration.mgt.core.dao.ConfigurationDAO) HashSet(java.util.HashSet) DB_SCHEMA_COLUMN_NAME_ATTRIBUTE_KEY(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.DB_SCHEMA_COLUMN_NAME_ATTRIBUTE_KEY) PrimitiveConditionValidationException(org.wso2.carbon.identity.configuration.mgt.core.search.exception.PrimitiveConditionValidationException) GET_RESOURCE_BY_ID_MYSQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.GET_RESOURCE_BY_ID_MYSQL) INSERT_OR_UPDATE_ATTRIBUTES_ORACLE(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_OR_UPDATE_ATTRIBUTES_ORACLE) INSERT_RESOURCE_SQL_WITHOUT_CREATED_TIME(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_RESOURCE_SQL_WITHOUT_CREATED_TIME) TransactionException(org.wso2.carbon.database.utils.jdbc.exceptions.TransactionException) GET_RESOURCE_BY_NAME_MYSQL_WITHOUT_CREATED_TIME(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.GET_RESOURCE_BY_NAME_MYSQL_WITHOUT_CREATED_TIME) INSERT_OR_UPDATE_RESOURCE_TYPE_POSTGRESQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_OR_UPDATE_RESOURCE_TYPE_POSTGRESQL) INSERT_OR_UPDATE_RESOURCE_MYSQL_WITHOUT_CREATED_TIME(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_OR_UPDATE_RESOURCE_MYSQL_WITHOUT_CREATED_TIME) GET_RESOURCE_BY_NAME_MYSQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.GET_RESOURCE_BY_NAME_MYSQL) UPDATE_LAST_MODIFIED_SQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.UPDATE_LAST_MODIFIED_SQL) ERROR_CODE_SEARCH_TENANT_RESOURCES(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_SEARCH_TENANT_RESOURCES) PlaceholderSQL(org.wso2.carbon.identity.configuration.mgt.core.search.PlaceholderSQL) JdbcUtils(org.wso2.carbon.identity.core.util.JdbcUtils) GET_TENANT_RESOURCES_SELECT_COLUMNS_MYSQL_WITHOUT_CREATED_TIME(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.GET_TENANT_RESOURCES_SELECT_COLUMNS_MYSQL_WITHOUT_CREATED_TIME) ConfigurationUtils.generateUniqueID(org.wso2.carbon.identity.configuration.mgt.core.util.ConfigurationUtils.generateUniqueID) GET_RESOURCE_ID_BY_NAME_SQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.GET_RESOURCE_ID_BY_NAME_SQL) DB_SCHEMA_COLUMN_NAME_NAME(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.DB_SCHEMA_COLUMN_NAME_NAME) GET_ATTRIBUTES_BY_RESOURCE_ID_SQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.GET_ATTRIBUTES_BY_RESOURCE_ID_SQL) DB_SCHEMA_COLUMN_NAME_TENANT_ID(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.DB_SCHEMA_COLUMN_NAME_TENANT_ID) DB_SCHEMA_COLUMN_NAME_RESOURCE_ID(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.DB_SCHEMA_COLUMN_NAME_RESOURCE_ID) JdbcUtils.isMySQLDB(org.wso2.carbon.identity.core.util.JdbcUtils.isMySQLDB) Attribute(org.wso2.carbon.identity.configuration.mgt.core.model.Attribute) ConfigurationUtils.useCreatedTimeField(org.wso2.carbon.identity.configuration.mgt.core.util.ConfigurationUtils.useCreatedTimeField) INSERT_OR_UPDATE_RESOURCE_TYPE_ORACLE(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_OR_UPDATE_RESOURCE_TYPE_ORACLE) UPDATE_RESOURCE(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.UPDATE_RESOURCE) ResourceSearchBean(org.wso2.carbon.identity.configuration.mgt.core.model.ResourceSearchBean) ERROR_CODE_DELETE_RESOURCE_TYPE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_DELETE_RESOURCE_TYPE) DELETE_FILE_SQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.DELETE_FILE_SQL) JdbcUtils.isPostgreSQLDB(org.wso2.carbon.identity.core.util.JdbcUtils.isPostgreSQLDB) INSERT_OR_UPDATE_RESOURCE_MYSQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_OR_UPDATE_RESOURCE_MYSQL) Log(org.apache.commons.logging.Log) Blob(java.sql.Blob) ConfigurationUtils.getFilePath(org.wso2.carbon.identity.configuration.mgt.core.util.ConfigurationUtils.getFilePath) ERROR_CODE_GET_RESOURCE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_GET_RESOURCE) JdbcUtils.isDB2DB(org.wso2.carbon.identity.core.util.JdbcUtils.isDB2DB) InputStream(java.io.InputStream) JdbcTemplate(org.wso2.carbon.database.utils.jdbc.JdbcTemplate) DataAccessException(org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException)

Example 2 with ERROR_CODE_CHECK_DB_METADATA

use of org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_CHECK_DB_METADATA in project carbon-identity-framework by wso2.

the class ConfigurationDAOImpl method addResource.

/**
 * {@inheritDoc}
 */
@Override
public void addResource(Resource resource) throws ConfigurationManagementException {
    String resourceTypeId = getResourceTypeByName(resource.getResourceType()).getId();
    Timestamp currentTime = new java.sql.Timestamp(new Date().getTime());
    JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();
    try {
        boolean isOracleOrMssql = isOracleDB() || isMSSqlDB();
        jdbcTemplate.withTransaction(template -> {
            boolean isAttributeExists = resource.getAttributes() != null;
            boolean isFileExists = resource.getFiles() != null && !resource.getFiles().isEmpty();
            // Insert resource metadata.
            template.executeInsert(useCreatedTimeField() ? INSERT_RESOURCE_SQL : INSERT_RESOURCE_SQL_WITHOUT_CREATED_TIME, preparedStatement -> {
                int initialParameterIndex = 1;
                preparedStatement.setString(initialParameterIndex, resource.getResourceId());
                preparedStatement.setInt(++initialParameterIndex, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
                preparedStatement.setString(++initialParameterIndex, resource.getResourceName());
                if (useCreatedTimeField()) {
                    preparedStatement.setTimestamp(++initialParameterIndex, currentTime, calendar);
                }
                preparedStatement.setTimestamp(++initialParameterIndex, currentTime, calendar);
                if (isOracleOrMssql) {
                    preparedStatement.setInt(++initialParameterIndex, isFileExists ? 1 : 0);
                    preparedStatement.setInt(++initialParameterIndex, isAttributeExists ? 1 : 0);
                } else {
                    preparedStatement.setBoolean(++initialParameterIndex, isFileExists);
                    preparedStatement.setBoolean(++initialParameterIndex, isAttributeExists);
                }
                preparedStatement.setString(++initialParameterIndex, resourceTypeId);
            }, resource, false);
            // Insert attributes.
            if (isAttributeExists) {
                insertResourceAttributes(template, resource);
            }
            // Insert files.
            if (isFileExists) {
                for (ResourceFile file : resource.getFiles()) {
                    insertResourceFile(template, resource, file.getId(), file.getName(), file.getInputStream());
                }
            }
            return null;
        });
        resource.setLastModified(currentTime.toInstant().toString());
        if (useCreatedTimeField()) {
            resource.setCreatedTime(currentTime.toInstant().toString());
        }
    } catch (TransactionException e) {
        throw handleServerException(ERROR_CODE_ADD_RESOURCE, resource.getResourceName(), e);
    } catch (DataAccessException e) {
        throw handleServerException(ERROR_CODE_CHECK_DB_METADATA, e.getMessage(), e);
    }
}
Also used : ResourceFile(org.wso2.carbon.identity.configuration.mgt.core.model.ResourceFile) TransactionException(org.wso2.carbon.database.utils.jdbc.exceptions.TransactionException) JdbcTemplate(org.wso2.carbon.database.utils.jdbc.JdbcTemplate) Timestamp(java.sql.Timestamp) Date(java.util.Date) DataAccessException(org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException)

Example 3 with ERROR_CODE_CHECK_DB_METADATA

use of org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_CHECK_DB_METADATA in project carbon-identity-framework by wso2.

the class ConfigurationDAOImpl method updateMetadataForMYSQL.

private void updateMetadataForMYSQL(Resource resource, String resourceTypeId, boolean isAttributeExists, Timestamp currentTime, boolean useCreatedTime) throws TransactionException, ConfigurationManagementServerException {
    String query = INSERT_OR_UPDATE_RESOURCE_MYSQL;
    try {
        if (isPostgreSQLDB()) {
            query = INSERT_OR_UPDATE_RESOURCE_POSTGRESQL;
        } else if (isMSSqlDB() || isDB2DB()) {
            query = INSERT_OR_UPDATE_RESOURCE_MSSQL_OR_DB2;
        } else if (isOracleDB()) {
            query = INSERT_OR_UPDATE_RESOURCE_ORACLE;
        }
        boolean isOracleOrMssql = isOracleDB() || isMSSqlDB();
        JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();
        final String finalQuery = query;
        jdbcTemplate.withTransaction(template -> template.executeInsert(useCreatedTime ? finalQuery : INSERT_OR_UPDATE_RESOURCE_MYSQL_WITHOUT_CREATED_TIME, preparedStatement -> {
            int initialParameterIndex = 1;
            preparedStatement.setString(initialParameterIndex, resource.getResourceId());
            preparedStatement.setInt(++initialParameterIndex, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
            preparedStatement.setString(++initialParameterIndex, resource.getResourceName());
            if (useCreatedTime) {
                preparedStatement.setTimestamp(++initialParameterIndex, currentTime, calendar);
            }
            preparedStatement.setTimestamp(++initialParameterIndex, currentTime, calendar);
            if (isOracleOrMssql) {
                preparedStatement.setInt(++initialParameterIndex, 0);
                preparedStatement.setInt(++initialParameterIndex, isAttributeExists ? 1 : 0);
            } else {
                preparedStatement.setBoolean(++initialParameterIndex, false);
                preparedStatement.setBoolean(++initialParameterIndex, isAttributeExists);
            }
            preparedStatement.setString(++initialParameterIndex, resourceTypeId);
        }, resource, false));
    } catch (DataAccessException e) {
        throw handleServerException(ERROR_CODE_CHECK_DB_METADATA, e.getMessage(), e);
    }
}
Also used : INSERT_OR_UPDATE_RESOURCE_POSTGRESQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_OR_UPDATE_RESOURCE_POSTGRESQL) MAX_QUERY_LENGTH_IN_BYTES_SQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.MAX_QUERY_LENGTH_IN_BYTES_SQL) DELETE_FILES_SQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.DELETE_FILES_SQL) StringUtils(org.apache.commons.lang.StringUtils) DB_SCHEMA_COLUMN_NAME_LAST_MODIFIED(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.DB_SCHEMA_COLUMN_NAME_LAST_MODIFIED) ResourceType(org.wso2.carbon.identity.configuration.mgt.core.model.ResourceType) INSERT_OR_UPDATE_ATTRIBUTE_MYSQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_OR_UPDATE_ATTRIBUTE_MYSQL) DB_SCHEMA_COLUMN_NAME_HAS_ATTRIBUTE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.DB_SCHEMA_COLUMN_NAME_HAS_ATTRIBUTE) DB_SCHEMA_COLUMN_NAME_CREATED_TIME(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.DB_SCHEMA_COLUMN_NAME_CREATED_TIME) ConfigurationManagementException(org.wso2.carbon.identity.configuration.mgt.core.exception.ConfigurationManagementException) INSERT_RESOURCE_SQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_RESOURCE_SQL) ERROR_CODE_INSERT_FILE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_INSERT_FILE) ERROR_CODE_GET_FILE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_GET_FILE) Map(java.util.Map) Condition(org.wso2.carbon.identity.configuration.mgt.core.search.Condition) ERROR_CODE_REPLACE_ATTRIBUTE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_REPLACE_ATTRIBUTE) ERROR_CODE_RESOURCE_ALREADY_EXISTS(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_RESOURCE_ALREADY_EXISTS) INSERT_OR_UPDATE_RESOURCE_MSSQL_OR_DB2(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_OR_UPDATE_RESOURCE_MSSQL_OR_DB2) INSERT_OR_UPDATE_ATTRIBUTES_POSTGRESQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_OR_UPDATE_ATTRIBUTES_POSTGRESQL) DB_SCHEMA_COLUMN_NAME_ATTRIBUTE_VALUE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.DB_SCHEMA_COLUMN_NAME_ATTRIBUTE_VALUE) INSERT_OR_UPDATE_ATTRIBUTES_MSSQL_OR_DB2(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_OR_UPDATE_ATTRIBUTES_MSSQL_OR_DB2) LambdaExceptionUtils(org.wso2.carbon.identity.core.util.LambdaExceptionUtils) ConfigurationUtils.getMaximumQueryLengthInBytes(org.wso2.carbon.identity.configuration.mgt.core.util.ConfigurationUtils.getMaximumQueryLengthInBytes) Set(java.util.Set) GET_RESOURCE_BY_ID_MYSQL_WITHOUT_CREATED_TIME(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.GET_RESOURCE_BY_ID_MYSQL_WITHOUT_CREATED_TIME) PreparedStatement(java.sql.PreparedStatement) SQLConstants(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants) JdbcUtils.isOracleDB(org.wso2.carbon.identity.core.util.JdbcUtils.isOracleDB) ERROR_CODE_UPDATE_ATTRIBUTE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_UPDATE_ATTRIBUTE) ConfigurationManagementClientException(org.wso2.carbon.identity.configuration.mgt.core.exception.ConfigurationManagementClientException) INSERT_OR_UPDATE_ATTRIBUTE_MSSQL_OR_DB2(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_OR_UPDATE_ATTRIBUTE_MSSQL_OR_DB2) GET_RESOURCE_TYPE_ID_BY_NAME_SQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.GET_RESOURCE_TYPE_ID_BY_NAME_SQL) LogFactory(org.apache.commons.logging.LogFactory) ERROR_CODE_INSERT_ATTRIBUTE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_INSERT_ATTRIBUTE) ERROR_CODE_DELETE_FILE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_DELETE_FILE) ERROR_CODE_SEARCH_QUERY_SQL_PROPERTY_PARSE_ERROR(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_SEARCH_QUERY_SQL_PROPERTY_PARSE_ERROR) GET_FILES_BY_RESOURCE_TYPE_ID_SQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.GET_FILES_BY_RESOURCE_TYPE_ID_SQL) JdbcTemplate(org.wso2.carbon.database.utils.jdbc.JdbcTemplate) ERROR_CODE_ADD_RESOURCE_TYPE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_ADD_RESOURCE_TYPE) ERROR_CODE_ADD_RESOURCE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_ADD_RESOURCE) ResourceFile(org.wso2.carbon.identity.configuration.mgt.core.model.ResourceFile) SQLIntegrityConstraintViolationException(java.sql.SQLIntegrityConstraintViolationException) INSERT_OR_UPDATE_RESOURCE_ORACLE(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_OR_UPDATE_RESOURCE_ORACLE) INSERT_OR_UPDATE_RESOURCE_TYPE_H2(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_OR_UPDATE_RESOURCE_TYPE_H2) ArrayList(java.util.ArrayList) SQLException(java.sql.SQLException) Calendar(java.util.Calendar) INSERT_OR_UPDATE_RESOURCE_TYPE_MSSQL_OR_DB2(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_OR_UPDATE_RESOURCE_TYPE_MSSQL_OR_DB2) DB_SCHEMA_COLUMN_NAME_RESOURCE_TYPE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.DB_SCHEMA_COLUMN_NAME_RESOURCE_TYPE) IdentityTenantUtil(org.wso2.carbon.identity.core.util.IdentityTenantUtil) ERROR_CODE_QUERY_LENGTH_EXCEEDED(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_QUERY_LENGTH_EXCEEDED) DB_SCHEMA_COLUMN_NAME_DESCRIPTTION(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.DB_SCHEMA_COLUMN_NAME_DESCRIPTTION) INSERT_OR_UPDATE_ATTRIBUTE_H2(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_OR_UPDATE_ATTRIBUTE_H2) GET_TENANT_RESOURCES_SELECT_COLUMNS_MSSQL_OR_ORACLE(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.GET_TENANT_RESOURCES_SELECT_COLUMNS_MSSQL_OR_ORACLE) UPDATE_HAS_FILE_SQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.UPDATE_HAS_FILE_SQL) JdbcUtils.isMSSqlDB(org.wso2.carbon.identity.core.util.JdbcUtils.isMSSqlDB) DB_SCHEMA_COLUMN_NAME_ATTRIBUTE_ID(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.DB_SCHEMA_COLUMN_NAME_ATTRIBUTE_ID) ERROR_CODE_DELETE_RESOURCE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_DELETE_RESOURCE) ERROR_CODE_REPLACE_RESOURCE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_REPLACE_RESOURCE) GET_RESOURCE_CREATED_TIME_BY_NAME_SQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.GET_RESOURCE_CREATED_TIME_BY_NAME_SQL) GET_RESOURCE_BY_ID_MSSQL_OR_ORACLE(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.GET_RESOURCE_BY_ID_MSSQL_OR_ORACLE) DB_SCHEMA_COLUMN_NAME_HAS_FILE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.DB_SCHEMA_COLUMN_NAME_HAS_FILE) GET_FILES_BY_RESOURCE_ID_SQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.GET_FILES_BY_RESOURCE_ID_SQL) ERROR_CODE_DELETE_ATTRIBUTE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_DELETE_ATTRIBUTE) ERROR_CODE_CHECK_DB_METADATA(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_CHECK_DB_METADATA) GET_RESOURCE_BY_NAME_MSSQL_OR_ORACLE(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.GET_RESOURCE_BY_NAME_MSSQL_OR_ORACLE) ERROR_CODE_UPDATE_RESOURCE_TYPE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_UPDATE_RESOURCE_TYPE) Resources(org.wso2.carbon.identity.configuration.mgt.core.model.Resources) DB_SCHEMA_COLUMN_NAME_ID(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.DB_SCHEMA_COLUMN_NAME_ID) UPDATE_RESOURCE_H2(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.UPDATE_RESOURCE_H2) INSERT_OR_UPDATE_ATTRIBUTES_MYSQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_OR_UPDATE_ATTRIBUTES_MYSQL) ConfigurationUtils.handleClientException(org.wso2.carbon.identity.configuration.mgt.core.util.ConfigurationUtils.handleClientException) DB_SCHEMA_COLUMN_NAME_RESOURCE_NAME(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.DB_SCHEMA_COLUMN_NAME_RESOURCE_NAME) Date(java.util.Date) Template(org.wso2.carbon.database.utils.jdbc.Template) DB_SCHEMA_COLUMN_NAME_FILE_NAME(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.DB_SCHEMA_COLUMN_NAME_FILE_NAME) ERROR_CODE_GET_ATTRIBUTE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_GET_ATTRIBUTE) DB_SCHEMA_COLUMN_NAME_RESOURCE_TYPE_NAME(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.DB_SCHEMA_COLUMN_NAME_RESOURCE_TYPE_NAME) GET_RESOURCE_NAME_BY_ID(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.GET_RESOURCE_NAME_BY_ID) DB_SCHEMA_COLUMN_NAME_VALUE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.DB_SCHEMA_COLUMN_NAME_VALUE) Resource(org.wso2.carbon.identity.configuration.mgt.core.model.Resource) ERROR_CODE_RESOURCES_DOES_NOT_EXISTS(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_RESOURCES_DOES_NOT_EXISTS) GET_RESOURCES_BY_RESOURCE_TYPE_ID_SQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.GET_RESOURCES_BY_RESOURCE_TYPE_ID_SQL) DB_SCHEMA_COLUMN_NAME_FILE_ID(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.DB_SCHEMA_COLUMN_NAME_FILE_ID) INSERT_OR_UPDATE_ATTRIBUTE_ORACLE(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_OR_UPDATE_ATTRIBUTE_ORACLE) ERROR_CODE_GET_FILES(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_GET_FILES) TimeZone(java.util.TimeZone) Timestamp(java.sql.Timestamp) PrimitiveConditionValidator(org.wso2.carbon.identity.configuration.mgt.core.search.PrimitiveConditionValidator) DELETE_ATTRIBUTE_SQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.DELETE_ATTRIBUTE_SQL) ERROR_CODE_RETRIEVE_RESOURCE_TYPE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_RETRIEVE_RESOURCE_TYPE) JdbcUtils.isMariaDB(org.wso2.carbon.identity.core.util.JdbcUtils.isMariaDB) ERROR_CODE_DELETE_FILES(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_DELETE_FILES) INSERT_OR_UPDATE_ATTRIBUTE_POSTGRESQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_OR_UPDATE_ATTRIBUTE_POSTGRESQL) ConfigurationManagementServerException(org.wso2.carbon.identity.configuration.mgt.core.exception.ConfigurationManagementServerException) List(java.util.List) DELETE_RESOURCE_ATTRIBUTES_SQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.DELETE_RESOURCE_ATTRIBUTES_SQL) JdbcUtils.isH2DB(org.wso2.carbon.identity.core.util.JdbcUtils.isH2DB) ConfigurationUtils.handleServerException(org.wso2.carbon.identity.configuration.mgt.core.util.ConfigurationUtils.handleServerException) DataAccessException(org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException) UTC(java.time.ZoneOffset.UTC) GET_TENANT_RESOURCES_SELECT_COLUMNS_MYSQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.GET_TENANT_RESOURCES_SELECT_COLUMNS_MYSQL) GET_RESOURCE_ID_TENANT_ID_BY_TYPE_ID_SQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.GET_RESOURCE_ID_TENANT_ID_BY_TYPE_ID_SQL) ERROR_CODE_GET_FILES_BY_TYPE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_GET_FILES_BY_TYPE) PrivilegedCarbonContext(org.wso2.carbon.context.PrivilegedCarbonContext) HashMap(java.util.HashMap) ConfigurationDAO(org.wso2.carbon.identity.configuration.mgt.core.dao.ConfigurationDAO) HashSet(java.util.HashSet) DB_SCHEMA_COLUMN_NAME_ATTRIBUTE_KEY(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.DB_SCHEMA_COLUMN_NAME_ATTRIBUTE_KEY) PrimitiveConditionValidationException(org.wso2.carbon.identity.configuration.mgt.core.search.exception.PrimitiveConditionValidationException) GET_RESOURCE_BY_ID_MYSQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.GET_RESOURCE_BY_ID_MYSQL) INSERT_OR_UPDATE_ATTRIBUTES_ORACLE(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_OR_UPDATE_ATTRIBUTES_ORACLE) INSERT_RESOURCE_SQL_WITHOUT_CREATED_TIME(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_RESOURCE_SQL_WITHOUT_CREATED_TIME) TransactionException(org.wso2.carbon.database.utils.jdbc.exceptions.TransactionException) GET_RESOURCE_BY_NAME_MYSQL_WITHOUT_CREATED_TIME(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.GET_RESOURCE_BY_NAME_MYSQL_WITHOUT_CREATED_TIME) INSERT_OR_UPDATE_RESOURCE_TYPE_POSTGRESQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_OR_UPDATE_RESOURCE_TYPE_POSTGRESQL) INSERT_OR_UPDATE_RESOURCE_MYSQL_WITHOUT_CREATED_TIME(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_OR_UPDATE_RESOURCE_MYSQL_WITHOUT_CREATED_TIME) GET_RESOURCE_BY_NAME_MYSQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.GET_RESOURCE_BY_NAME_MYSQL) UPDATE_LAST_MODIFIED_SQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.UPDATE_LAST_MODIFIED_SQL) ERROR_CODE_SEARCH_TENANT_RESOURCES(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_SEARCH_TENANT_RESOURCES) PlaceholderSQL(org.wso2.carbon.identity.configuration.mgt.core.search.PlaceholderSQL) JdbcUtils(org.wso2.carbon.identity.core.util.JdbcUtils) GET_TENANT_RESOURCES_SELECT_COLUMNS_MYSQL_WITHOUT_CREATED_TIME(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.GET_TENANT_RESOURCES_SELECT_COLUMNS_MYSQL_WITHOUT_CREATED_TIME) ConfigurationUtils.generateUniqueID(org.wso2.carbon.identity.configuration.mgt.core.util.ConfigurationUtils.generateUniqueID) GET_RESOURCE_ID_BY_NAME_SQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.GET_RESOURCE_ID_BY_NAME_SQL) DB_SCHEMA_COLUMN_NAME_NAME(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.DB_SCHEMA_COLUMN_NAME_NAME) GET_ATTRIBUTES_BY_RESOURCE_ID_SQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.GET_ATTRIBUTES_BY_RESOURCE_ID_SQL) DB_SCHEMA_COLUMN_NAME_TENANT_ID(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.DB_SCHEMA_COLUMN_NAME_TENANT_ID) DB_SCHEMA_COLUMN_NAME_RESOURCE_ID(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.DB_SCHEMA_COLUMN_NAME_RESOURCE_ID) JdbcUtils.isMySQLDB(org.wso2.carbon.identity.core.util.JdbcUtils.isMySQLDB) Attribute(org.wso2.carbon.identity.configuration.mgt.core.model.Attribute) ConfigurationUtils.useCreatedTimeField(org.wso2.carbon.identity.configuration.mgt.core.util.ConfigurationUtils.useCreatedTimeField) INSERT_OR_UPDATE_RESOURCE_TYPE_ORACLE(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_OR_UPDATE_RESOURCE_TYPE_ORACLE) UPDATE_RESOURCE(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.UPDATE_RESOURCE) ResourceSearchBean(org.wso2.carbon.identity.configuration.mgt.core.model.ResourceSearchBean) ERROR_CODE_DELETE_RESOURCE_TYPE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_DELETE_RESOURCE_TYPE) DELETE_FILE_SQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.DELETE_FILE_SQL) JdbcUtils.isPostgreSQLDB(org.wso2.carbon.identity.core.util.JdbcUtils.isPostgreSQLDB) INSERT_OR_UPDATE_RESOURCE_MYSQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_OR_UPDATE_RESOURCE_MYSQL) Log(org.apache.commons.logging.Log) Blob(java.sql.Blob) ConfigurationUtils.getFilePath(org.wso2.carbon.identity.configuration.mgt.core.util.ConfigurationUtils.getFilePath) ERROR_CODE_GET_RESOURCE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_GET_RESOURCE) JdbcUtils.isDB2DB(org.wso2.carbon.identity.core.util.JdbcUtils.isDB2DB) InputStream(java.io.InputStream) JdbcTemplate(org.wso2.carbon.database.utils.jdbc.JdbcTemplate) DataAccessException(org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException)

Example 4 with ERROR_CODE_CHECK_DB_METADATA

use of org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_CHECK_DB_METADATA in project carbon-identity-framework by wso2.

the class ConfigurationDAOImpl method deleteFileById.

@Override
public void deleteFileById(String resourceType, String resourceName, String fileId) throws ConfigurationManagementException {
    JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();
    try {
        boolean isOracleOrMssql = isOracleDB() || isMSSqlDB();
        jdbcTemplate.withTransaction(template -> {
            // Get resource id for the deleting file.
            String sqlStmt = isH2DB() ? SQLConstants.GET_FILE_BY_ID_SQL_H2 : SQLConstants.GET_FILE_BY_ID_SQL;
            String resourceId = template.fetchSingleRecord(sqlStmt, (resultSet, rowNumber) -> resultSet.getString(DB_SCHEMA_COLUMN_NAME_RESOURCE_ID), preparedStatement -> {
                preparedStatement.setString(1, fileId);
                preparedStatement.setString(2, resourceName);
                preparedStatement.setString(3, resourceType);
            });
            template.executeUpdate(DELETE_FILE_SQL, (preparedStatement -> preparedStatement.setString(1, fileId)));
            List<String> availableFilesForTheResource = template.executeQuery(GET_FILES_BY_RESOURCE_ID_SQL, ((resultSet, rowNumber) -> resultSet.getString(DB_SCHEMA_COLUMN_NAME_ID)), preparedStatement -> preparedStatement.setString(1, resourceId));
            if (availableFilesForTheResource.isEmpty()) {
                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_FILE, fileId, e);
    } catch (DataAccessException e) {
        throw handleServerException(ERROR_CODE_CHECK_DB_METADATA, e.getMessage(), e);
    }
}
Also used : INSERT_OR_UPDATE_RESOURCE_POSTGRESQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_OR_UPDATE_RESOURCE_POSTGRESQL) MAX_QUERY_LENGTH_IN_BYTES_SQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.MAX_QUERY_LENGTH_IN_BYTES_SQL) DELETE_FILES_SQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.DELETE_FILES_SQL) StringUtils(org.apache.commons.lang.StringUtils) DB_SCHEMA_COLUMN_NAME_LAST_MODIFIED(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.DB_SCHEMA_COLUMN_NAME_LAST_MODIFIED) ResourceType(org.wso2.carbon.identity.configuration.mgt.core.model.ResourceType) INSERT_OR_UPDATE_ATTRIBUTE_MYSQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_OR_UPDATE_ATTRIBUTE_MYSQL) DB_SCHEMA_COLUMN_NAME_HAS_ATTRIBUTE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.DB_SCHEMA_COLUMN_NAME_HAS_ATTRIBUTE) DB_SCHEMA_COLUMN_NAME_CREATED_TIME(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.DB_SCHEMA_COLUMN_NAME_CREATED_TIME) ConfigurationManagementException(org.wso2.carbon.identity.configuration.mgt.core.exception.ConfigurationManagementException) INSERT_RESOURCE_SQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_RESOURCE_SQL) ERROR_CODE_INSERT_FILE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_INSERT_FILE) ERROR_CODE_GET_FILE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_GET_FILE) Map(java.util.Map) Condition(org.wso2.carbon.identity.configuration.mgt.core.search.Condition) ERROR_CODE_REPLACE_ATTRIBUTE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_REPLACE_ATTRIBUTE) ERROR_CODE_RESOURCE_ALREADY_EXISTS(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_RESOURCE_ALREADY_EXISTS) INSERT_OR_UPDATE_RESOURCE_MSSQL_OR_DB2(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_OR_UPDATE_RESOURCE_MSSQL_OR_DB2) INSERT_OR_UPDATE_ATTRIBUTES_POSTGRESQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_OR_UPDATE_ATTRIBUTES_POSTGRESQL) DB_SCHEMA_COLUMN_NAME_ATTRIBUTE_VALUE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.DB_SCHEMA_COLUMN_NAME_ATTRIBUTE_VALUE) INSERT_OR_UPDATE_ATTRIBUTES_MSSQL_OR_DB2(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_OR_UPDATE_ATTRIBUTES_MSSQL_OR_DB2) LambdaExceptionUtils(org.wso2.carbon.identity.core.util.LambdaExceptionUtils) ConfigurationUtils.getMaximumQueryLengthInBytes(org.wso2.carbon.identity.configuration.mgt.core.util.ConfigurationUtils.getMaximumQueryLengthInBytes) Set(java.util.Set) GET_RESOURCE_BY_ID_MYSQL_WITHOUT_CREATED_TIME(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.GET_RESOURCE_BY_ID_MYSQL_WITHOUT_CREATED_TIME) PreparedStatement(java.sql.PreparedStatement) SQLConstants(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants) JdbcUtils.isOracleDB(org.wso2.carbon.identity.core.util.JdbcUtils.isOracleDB) ERROR_CODE_UPDATE_ATTRIBUTE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_UPDATE_ATTRIBUTE) ConfigurationManagementClientException(org.wso2.carbon.identity.configuration.mgt.core.exception.ConfigurationManagementClientException) INSERT_OR_UPDATE_ATTRIBUTE_MSSQL_OR_DB2(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_OR_UPDATE_ATTRIBUTE_MSSQL_OR_DB2) GET_RESOURCE_TYPE_ID_BY_NAME_SQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.GET_RESOURCE_TYPE_ID_BY_NAME_SQL) LogFactory(org.apache.commons.logging.LogFactory) ERROR_CODE_INSERT_ATTRIBUTE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_INSERT_ATTRIBUTE) ERROR_CODE_DELETE_FILE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_DELETE_FILE) ERROR_CODE_SEARCH_QUERY_SQL_PROPERTY_PARSE_ERROR(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_SEARCH_QUERY_SQL_PROPERTY_PARSE_ERROR) GET_FILES_BY_RESOURCE_TYPE_ID_SQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.GET_FILES_BY_RESOURCE_TYPE_ID_SQL) JdbcTemplate(org.wso2.carbon.database.utils.jdbc.JdbcTemplate) ERROR_CODE_ADD_RESOURCE_TYPE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_ADD_RESOURCE_TYPE) ERROR_CODE_ADD_RESOURCE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_ADD_RESOURCE) ResourceFile(org.wso2.carbon.identity.configuration.mgt.core.model.ResourceFile) SQLIntegrityConstraintViolationException(java.sql.SQLIntegrityConstraintViolationException) INSERT_OR_UPDATE_RESOURCE_ORACLE(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_OR_UPDATE_RESOURCE_ORACLE) INSERT_OR_UPDATE_RESOURCE_TYPE_H2(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_OR_UPDATE_RESOURCE_TYPE_H2) ArrayList(java.util.ArrayList) SQLException(java.sql.SQLException) Calendar(java.util.Calendar) INSERT_OR_UPDATE_RESOURCE_TYPE_MSSQL_OR_DB2(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_OR_UPDATE_RESOURCE_TYPE_MSSQL_OR_DB2) DB_SCHEMA_COLUMN_NAME_RESOURCE_TYPE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.DB_SCHEMA_COLUMN_NAME_RESOURCE_TYPE) IdentityTenantUtil(org.wso2.carbon.identity.core.util.IdentityTenantUtil) ERROR_CODE_QUERY_LENGTH_EXCEEDED(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_QUERY_LENGTH_EXCEEDED) DB_SCHEMA_COLUMN_NAME_DESCRIPTTION(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.DB_SCHEMA_COLUMN_NAME_DESCRIPTTION) INSERT_OR_UPDATE_ATTRIBUTE_H2(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_OR_UPDATE_ATTRIBUTE_H2) GET_TENANT_RESOURCES_SELECT_COLUMNS_MSSQL_OR_ORACLE(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.GET_TENANT_RESOURCES_SELECT_COLUMNS_MSSQL_OR_ORACLE) UPDATE_HAS_FILE_SQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.UPDATE_HAS_FILE_SQL) JdbcUtils.isMSSqlDB(org.wso2.carbon.identity.core.util.JdbcUtils.isMSSqlDB) DB_SCHEMA_COLUMN_NAME_ATTRIBUTE_ID(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.DB_SCHEMA_COLUMN_NAME_ATTRIBUTE_ID) ERROR_CODE_DELETE_RESOURCE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_DELETE_RESOURCE) ERROR_CODE_REPLACE_RESOURCE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_REPLACE_RESOURCE) GET_RESOURCE_CREATED_TIME_BY_NAME_SQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.GET_RESOURCE_CREATED_TIME_BY_NAME_SQL) GET_RESOURCE_BY_ID_MSSQL_OR_ORACLE(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.GET_RESOURCE_BY_ID_MSSQL_OR_ORACLE) DB_SCHEMA_COLUMN_NAME_HAS_FILE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.DB_SCHEMA_COLUMN_NAME_HAS_FILE) GET_FILES_BY_RESOURCE_ID_SQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.GET_FILES_BY_RESOURCE_ID_SQL) ERROR_CODE_DELETE_ATTRIBUTE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_DELETE_ATTRIBUTE) ERROR_CODE_CHECK_DB_METADATA(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_CHECK_DB_METADATA) GET_RESOURCE_BY_NAME_MSSQL_OR_ORACLE(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.GET_RESOURCE_BY_NAME_MSSQL_OR_ORACLE) ERROR_CODE_UPDATE_RESOURCE_TYPE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_UPDATE_RESOURCE_TYPE) Resources(org.wso2.carbon.identity.configuration.mgt.core.model.Resources) DB_SCHEMA_COLUMN_NAME_ID(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.DB_SCHEMA_COLUMN_NAME_ID) UPDATE_RESOURCE_H2(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.UPDATE_RESOURCE_H2) INSERT_OR_UPDATE_ATTRIBUTES_MYSQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_OR_UPDATE_ATTRIBUTES_MYSQL) ConfigurationUtils.handleClientException(org.wso2.carbon.identity.configuration.mgt.core.util.ConfigurationUtils.handleClientException) DB_SCHEMA_COLUMN_NAME_RESOURCE_NAME(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.DB_SCHEMA_COLUMN_NAME_RESOURCE_NAME) Date(java.util.Date) Template(org.wso2.carbon.database.utils.jdbc.Template) DB_SCHEMA_COLUMN_NAME_FILE_NAME(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.DB_SCHEMA_COLUMN_NAME_FILE_NAME) ERROR_CODE_GET_ATTRIBUTE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_GET_ATTRIBUTE) DB_SCHEMA_COLUMN_NAME_RESOURCE_TYPE_NAME(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.DB_SCHEMA_COLUMN_NAME_RESOURCE_TYPE_NAME) GET_RESOURCE_NAME_BY_ID(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.GET_RESOURCE_NAME_BY_ID) DB_SCHEMA_COLUMN_NAME_VALUE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.DB_SCHEMA_COLUMN_NAME_VALUE) Resource(org.wso2.carbon.identity.configuration.mgt.core.model.Resource) ERROR_CODE_RESOURCES_DOES_NOT_EXISTS(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_RESOURCES_DOES_NOT_EXISTS) GET_RESOURCES_BY_RESOURCE_TYPE_ID_SQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.GET_RESOURCES_BY_RESOURCE_TYPE_ID_SQL) DB_SCHEMA_COLUMN_NAME_FILE_ID(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.DB_SCHEMA_COLUMN_NAME_FILE_ID) INSERT_OR_UPDATE_ATTRIBUTE_ORACLE(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_OR_UPDATE_ATTRIBUTE_ORACLE) ERROR_CODE_GET_FILES(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_GET_FILES) TimeZone(java.util.TimeZone) Timestamp(java.sql.Timestamp) PrimitiveConditionValidator(org.wso2.carbon.identity.configuration.mgt.core.search.PrimitiveConditionValidator) DELETE_ATTRIBUTE_SQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.DELETE_ATTRIBUTE_SQL) ERROR_CODE_RETRIEVE_RESOURCE_TYPE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_RETRIEVE_RESOURCE_TYPE) JdbcUtils.isMariaDB(org.wso2.carbon.identity.core.util.JdbcUtils.isMariaDB) ERROR_CODE_DELETE_FILES(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_DELETE_FILES) INSERT_OR_UPDATE_ATTRIBUTE_POSTGRESQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_OR_UPDATE_ATTRIBUTE_POSTGRESQL) ConfigurationManagementServerException(org.wso2.carbon.identity.configuration.mgt.core.exception.ConfigurationManagementServerException) List(java.util.List) DELETE_RESOURCE_ATTRIBUTES_SQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.DELETE_RESOURCE_ATTRIBUTES_SQL) JdbcUtils.isH2DB(org.wso2.carbon.identity.core.util.JdbcUtils.isH2DB) ConfigurationUtils.handleServerException(org.wso2.carbon.identity.configuration.mgt.core.util.ConfigurationUtils.handleServerException) DataAccessException(org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException) UTC(java.time.ZoneOffset.UTC) GET_TENANT_RESOURCES_SELECT_COLUMNS_MYSQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.GET_TENANT_RESOURCES_SELECT_COLUMNS_MYSQL) GET_RESOURCE_ID_TENANT_ID_BY_TYPE_ID_SQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.GET_RESOURCE_ID_TENANT_ID_BY_TYPE_ID_SQL) ERROR_CODE_GET_FILES_BY_TYPE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_GET_FILES_BY_TYPE) PrivilegedCarbonContext(org.wso2.carbon.context.PrivilegedCarbonContext) HashMap(java.util.HashMap) ConfigurationDAO(org.wso2.carbon.identity.configuration.mgt.core.dao.ConfigurationDAO) HashSet(java.util.HashSet) DB_SCHEMA_COLUMN_NAME_ATTRIBUTE_KEY(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.DB_SCHEMA_COLUMN_NAME_ATTRIBUTE_KEY) PrimitiveConditionValidationException(org.wso2.carbon.identity.configuration.mgt.core.search.exception.PrimitiveConditionValidationException) GET_RESOURCE_BY_ID_MYSQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.GET_RESOURCE_BY_ID_MYSQL) INSERT_OR_UPDATE_ATTRIBUTES_ORACLE(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_OR_UPDATE_ATTRIBUTES_ORACLE) INSERT_RESOURCE_SQL_WITHOUT_CREATED_TIME(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_RESOURCE_SQL_WITHOUT_CREATED_TIME) TransactionException(org.wso2.carbon.database.utils.jdbc.exceptions.TransactionException) GET_RESOURCE_BY_NAME_MYSQL_WITHOUT_CREATED_TIME(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.GET_RESOURCE_BY_NAME_MYSQL_WITHOUT_CREATED_TIME) INSERT_OR_UPDATE_RESOURCE_TYPE_POSTGRESQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_OR_UPDATE_RESOURCE_TYPE_POSTGRESQL) INSERT_OR_UPDATE_RESOURCE_MYSQL_WITHOUT_CREATED_TIME(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_OR_UPDATE_RESOURCE_MYSQL_WITHOUT_CREATED_TIME) GET_RESOURCE_BY_NAME_MYSQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.GET_RESOURCE_BY_NAME_MYSQL) UPDATE_LAST_MODIFIED_SQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.UPDATE_LAST_MODIFIED_SQL) ERROR_CODE_SEARCH_TENANT_RESOURCES(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_SEARCH_TENANT_RESOURCES) PlaceholderSQL(org.wso2.carbon.identity.configuration.mgt.core.search.PlaceholderSQL) JdbcUtils(org.wso2.carbon.identity.core.util.JdbcUtils) GET_TENANT_RESOURCES_SELECT_COLUMNS_MYSQL_WITHOUT_CREATED_TIME(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.GET_TENANT_RESOURCES_SELECT_COLUMNS_MYSQL_WITHOUT_CREATED_TIME) ConfigurationUtils.generateUniqueID(org.wso2.carbon.identity.configuration.mgt.core.util.ConfigurationUtils.generateUniqueID) GET_RESOURCE_ID_BY_NAME_SQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.GET_RESOURCE_ID_BY_NAME_SQL) DB_SCHEMA_COLUMN_NAME_NAME(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.DB_SCHEMA_COLUMN_NAME_NAME) GET_ATTRIBUTES_BY_RESOURCE_ID_SQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.GET_ATTRIBUTES_BY_RESOURCE_ID_SQL) DB_SCHEMA_COLUMN_NAME_TENANT_ID(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.DB_SCHEMA_COLUMN_NAME_TENANT_ID) DB_SCHEMA_COLUMN_NAME_RESOURCE_ID(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.DB_SCHEMA_COLUMN_NAME_RESOURCE_ID) JdbcUtils.isMySQLDB(org.wso2.carbon.identity.core.util.JdbcUtils.isMySQLDB) Attribute(org.wso2.carbon.identity.configuration.mgt.core.model.Attribute) ConfigurationUtils.useCreatedTimeField(org.wso2.carbon.identity.configuration.mgt.core.util.ConfigurationUtils.useCreatedTimeField) INSERT_OR_UPDATE_RESOURCE_TYPE_ORACLE(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_OR_UPDATE_RESOURCE_TYPE_ORACLE) UPDATE_RESOURCE(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.UPDATE_RESOURCE) ResourceSearchBean(org.wso2.carbon.identity.configuration.mgt.core.model.ResourceSearchBean) ERROR_CODE_DELETE_RESOURCE_TYPE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_DELETE_RESOURCE_TYPE) DELETE_FILE_SQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.DELETE_FILE_SQL) JdbcUtils.isPostgreSQLDB(org.wso2.carbon.identity.core.util.JdbcUtils.isPostgreSQLDB) INSERT_OR_UPDATE_RESOURCE_MYSQL(org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_OR_UPDATE_RESOURCE_MYSQL) Log(org.apache.commons.logging.Log) Blob(java.sql.Blob) ConfigurationUtils.getFilePath(org.wso2.carbon.identity.configuration.mgt.core.util.ConfigurationUtils.getFilePath) ERROR_CODE_GET_RESOURCE(org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_GET_RESOURCE) JdbcUtils.isDB2DB(org.wso2.carbon.identity.core.util.JdbcUtils.isDB2DB) InputStream(java.io.InputStream) TransactionException(org.wso2.carbon.database.utils.jdbc.exceptions.TransactionException) JdbcTemplate(org.wso2.carbon.database.utils.jdbc.JdbcTemplate) DataAccessException(org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException)

Example 5 with ERROR_CODE_CHECK_DB_METADATA

use of org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_CHECK_DB_METADATA in project carbon-identity-framework by wso2.

the class ConfigurationDAOImpl method addFile.

@Override
public void addFile(String fileId, String resourceId, String fileName, InputStream fileStream) throws ConfigurationManagementException {
    JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();
    try {
        boolean isOracleOrMssql = isOracleDB() || isMSSqlDB();
        boolean isPostgreSQL = isPostgreSQLDB();
        String sqlStmt = isH2DB() ? SQLConstants.INSERT_FILE_SQL_H2 : SQLConstants.INSERT_FILE_SQL;
        jdbcTemplate.withTransaction(template -> {
            template.executeUpdate(sqlStmt, preparedStatement -> {
                preparedStatement.setString(1, fileId);
                if (isPostgreSQL) {
                    preparedStatement.setBinaryStream(2, fileStream);
                } else {
                    preparedStatement.setBlob(2, fileStream);
                }
                preparedStatement.setString(3, resourceId);
                preparedStatement.setString(4, fileName);
            });
            template.executeUpdate(SQLConstants.UPDATE_HAS_FILE_SQL, preparedStatement -> {
                if (isOracleOrMssql) {
                    preparedStatement.setInt(1, 1);
                } else {
                    preparedStatement.setBoolean(1, true);
                }
                preparedStatement.setString(2, resourceId);
            });
            updateResourceLastModified(template, resourceId);
            return null;
        });
    } catch (TransactionException e) {
        throw handleServerException(ERROR_CODE_INSERT_FILE, fileId, e);
    } catch (DataAccessException e) {
        throw handleServerException(ERROR_CODE_CHECK_DB_METADATA, e.getMessage(), e);
    }
}
Also used : TransactionException(org.wso2.carbon.database.utils.jdbc.exceptions.TransactionException) JdbcTemplate(org.wso2.carbon.database.utils.jdbc.JdbcTemplate) DataAccessException(org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException)

Aggregations

DataAccessException (org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException)7 JdbcTemplate (org.wso2.carbon.database.utils.jdbc.JdbcTemplate)6 TransactionException (org.wso2.carbon.database.utils.jdbc.exceptions.TransactionException)6 Timestamp (java.sql.Timestamp)5 Date (java.util.Date)5 ResourceFile (org.wso2.carbon.identity.configuration.mgt.core.model.ResourceFile)5 ResourceSearchBean (org.wso2.carbon.identity.configuration.mgt.core.model.ResourceSearchBean)5 PlaceholderSQL (org.wso2.carbon.identity.configuration.mgt.core.search.PlaceholderSQL)5 PrimitiveConditionValidator (org.wso2.carbon.identity.configuration.mgt.core.search.PrimitiveConditionValidator)5 PrimitiveConditionValidationException (org.wso2.carbon.identity.configuration.mgt.core.search.exception.PrimitiveConditionValidationException)5 InputStream (java.io.InputStream)4 Blob (java.sql.Blob)4 PreparedStatement (java.sql.PreparedStatement)4 SQLException (java.sql.SQLException)4 SQLIntegrityConstraintViolationException (java.sql.SQLIntegrityConstraintViolationException)4 UTC (java.time.ZoneOffset.UTC)4 ArrayList (java.util.ArrayList)4 Calendar (java.util.Calendar)4 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4