Search in sources :

Example 1 with TransactionException

use of org.wso2.carbon.database.utils.jdbc.exceptions.TransactionException in project carbon-identity-framework by wso2.

the class UserSessionStore method storeAppSessionDataIfNotExist.

/**
 * Method to store app session data if the particular app session is not already exists in the database.
 *
 * @param sessionId   Id of the authenticated session.
 * @param subject     Username in application.
 * @param appID       Id of the application.
 * @param inboundAuth Protocol used in the app.
 * @throws DataAccessException if an error occurs when storing the authenticated user details to the database.
 * @deprecated Please use storeAppSessionData method instead.
 */
@Deprecated
public void storeAppSessionDataIfNotExist(String sessionId, String subject, int appID, String inboundAuth) throws DataAccessException {
    JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate(JdbcUtils.Database.SESSION);
    try {
        jdbcTemplate.withTransaction(template -> {
            Integer recordCount = template.fetchSingleRecord(SQLQueries.SQL_CHECK_IDN_AUTH_SESSION_APP_INFO, (resultSet, rowNumber) -> resultSet.getInt(1), preparedStatement -> {
                preparedStatement.setString(1, sessionId);
                preparedStatement.setString(2, subject);
                preparedStatement.setInt(3, appID);
                preparedStatement.setString(4, inboundAuth);
            });
            if (recordCount == null) {
                storeAppSessionData(sessionId, subject, appID, inboundAuth);
            }
            return null;
        });
    } catch (TransactionException e) {
        throw new DataAccessException("Error while storing application data of session id: " + sessionId + ", subject: " + subject + ", app Id: " + appID + ", protocol: " + inboundAuth + ".", 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)

Example 2 with TransactionException

use of org.wso2.carbon.database.utils.jdbc.exceptions.TransactionException in project carbon-identity-framework by wso2.

the class ConfigurationDAOImpl method isResourceExists.

private boolean isResourceExists(Resource resource, String resourceTypeId) throws TransactionException {
    JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();
    String resourceId = jdbcTemplate.withTransaction(template -> template.fetchSingleRecord(GET_RESOURCE_ID_BY_NAME_SQL, (resultSet, rowNumber) -> resultSet.getString(DB_SCHEMA_COLUMN_NAME_ID), preparedStatement -> {
        int initialParameterIndex = 1;
        preparedStatement.setString(initialParameterIndex, resource.getResourceName());
        preparedStatement.setInt(++initialParameterIndex, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
        preparedStatement.setString(++initialParameterIndex, resourceTypeId);
    }));
    return resourceId != null;
}
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)

Example 3 with TransactionException

use of org.wso2.carbon.database.utils.jdbc.exceptions.TransactionException in project carbon-identity-framework by wso2.

the class ConfigurationDAOImpl method addAttribute.

/**
 * {@inheritDoc}
 */
@Override
public void addAttribute(String attributeId, String resourceId, Attribute attribute) throws ConfigurationManagementException {
    JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();
    try {
        jdbcTemplate.withTransaction(template -> {
            template.executeUpdate(SQLConstants.INSERT_ATTRIBUTE_MYSQL, preparedStatement -> {
                int initialParameterIndex = 1;
                preparedStatement.setString(initialParameterIndex, attributeId);
                preparedStatement.setString(++initialParameterIndex, resourceId);
                preparedStatement.setString(++initialParameterIndex, attribute.getKey());
                preparedStatement.setString(++initialParameterIndex, attribute.getValue());
            });
            template.executeUpdate(SQLConstants.UPDATE_LAST_MODIFIED_SQL, preparedStatement -> {
                int initialParameterIndex = 1;
                preparedStatement.setTimestamp(initialParameterIndex, new java.sql.Timestamp(new Date().getTime()), calendar);
                preparedStatement.setString(++initialParameterIndex, resourceId);
            });
            return null;
        });
    } catch (TransactionException e) {
        throw handleServerException(ERROR_CODE_INSERT_ATTRIBUTE, attribute.getKey(), e);
    }
}
Also used : TransactionException(org.wso2.carbon.database.utils.jdbc.exceptions.TransactionException) Timestamp(java.sql.Timestamp) JdbcTemplate(org.wso2.carbon.database.utils.jdbc.JdbcTemplate) Date(java.util.Date)

Example 4 with TransactionException

use of org.wso2.carbon.database.utils.jdbc.exceptions.TransactionException in project carbon-identity-framework by wso2.

the class ConfigurationDAOImpl method replaceResource.

/**
 * {@inheritDoc}
 */
@Override
public void replaceResource(Resource resource) throws ConfigurationManagementException {
    String resourceTypeId = getResourceTypeByName(resource.getResourceType()).getId();
    Timestamp currentTime = new java.sql.Timestamp(new Date().getTime());
    JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();
    try {
        Timestamp createdTime = jdbcTemplate.withTransaction(template -> {
            boolean isAttributeExists = resource.getAttributes() != null;
            if (isH2DB()) {
                updateMetadataForH2(resource, resourceTypeId, isAttributeExists, currentTime, useCreatedTimeField());
            } else {
                updateMetadataForMYSQL(resource, resourceTypeId, isAttributeExists, currentTime, useCreatedTimeField());
            }
            // Insert attributes.
            if (isAttributeExists) {
                // Delete existing attributes.
                template.executeUpdate(DELETE_RESOURCE_ATTRIBUTES_SQL, preparedStatement -> preparedStatement.setString(1, resource.getResourceId()));
                insertResourceAttributes(template, resource);
            }
            if (useCreatedTimeField()) {
                return getCreatedTimeInResponse(resource, resourceTypeId);
            } else {
                return null;
            }
        });
        resource.setLastModified(currentTime.toInstant().toString());
        if (createdTime != null) {
            resource.setCreatedTime(createdTime.toInstant().toString());
        }
    } catch (TransactionException e) {
        throw handleServerException(ERROR_CODE_REPLACE_RESOURCE, resource.getResourceName(), e);
    }
}
Also used : 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)

Example 5 with TransactionException

use of org.wso2.carbon.database.utils.jdbc.exceptions.TransactionException in project identity-inbound-auth-oauth by wso2-extensions.

the class ScopeClaimMappingDAOImpl method getScopeId.

private int getScopeId(String scope, int tenantId) throws IdentityOAuth2Exception {
    Integer scopeId;
    try {
        JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();
        scopeId = jdbcTemplate.withTransaction(template -> template.fetchSingleRecord(SQLQueries.GET_IDN_OIDC_SCOPE_ID, (resultSet, rowNumber) -> resultSet.getInt(1), preparedStatement -> {
            preparedStatement.setString(1, scope);
            preparedStatement.setInt(2, tenantId);
            preparedStatement.setString(3, Oauth2ScopeConstants.SCOPE_TYPE_OIDC);
        }));
        if (scopeId == null) {
            scopeId = -1;
        }
        if (log.isDebugEnabled()) {
            log.debug("Scope id: " + scopeId + "is returned for the tenant: " + tenantId + "and scope: " + scope);
        }
    } catch (TransactionException e) {
        String errorMessage = "Error fetching data for oidc scope: " + scope;
        throw new IdentityOAuth2Exception(errorMessage, e);
    }
    return scopeId;
}
Also used : IdentityOAuth2ClientException(org.wso2.carbon.identity.oauth2.IdentityOAuth2ClientException) Arrays(java.util.Arrays) JdbcTemplate(org.wso2.carbon.database.utils.jdbc.JdbcTemplate) LambdaExceptionUtils.rethrowConsumer(org.wso2.carbon.identity.core.util.LambdaExceptionUtils.rethrowConsumer) Oauth2ScopeConstants(org.wso2.carbon.identity.oauth2.Oauth2ScopeConstants) Set(java.util.Set) HashMap(java.util.HashMap) SQLIntegrityConstraintViolationException(java.sql.SQLIntegrityConstraintViolationException) JdbcUtils(org.wso2.carbon.identity.oauth2.util.JdbcUtils) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) List(java.util.List) CollectionUtils(org.apache.commons.collections.CollectionUtils) TransactionException(org.wso2.carbon.database.utils.jdbc.exceptions.TransactionException) DataAccessException(org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException) ScopeDTO(org.wso2.carbon.identity.oauth.dto.ScopeDTO) Map(java.util.Map) IdentityOAuth2Exception(org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception) Log(org.apache.commons.logging.Log) RowMapper(org.wso2.carbon.database.utils.jdbc.RowMapper) LogFactory(org.apache.commons.logging.LogFactory) ArrayUtils(org.apache.commons.lang.ArrayUtils) TransactionException(org.wso2.carbon.database.utils.jdbc.exceptions.TransactionException) IdentityOAuth2Exception(org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception) JdbcTemplate(org.wso2.carbon.database.utils.jdbc.JdbcTemplate)

Aggregations

TransactionException (org.wso2.carbon.database.utils.jdbc.exceptions.TransactionException)25 JdbcTemplate (org.wso2.carbon.database.utils.jdbc.JdbcTemplate)23 DataAccessException (org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException)18 Timestamp (java.sql.Timestamp)15 Date (java.util.Date)15 SQLIntegrityConstraintViolationException (java.sql.SQLIntegrityConstraintViolationException)13 ArrayList (java.util.ArrayList)13 HashMap (java.util.HashMap)13 HashSet (java.util.HashSet)13 List (java.util.List)13 Map (java.util.Map)13 Set (java.util.Set)13 Log (org.apache.commons.logging.Log)13 LogFactory (org.apache.commons.logging.LogFactory)13 InputStream (java.io.InputStream)8 Blob (java.sql.Blob)8 PreparedStatement (java.sql.PreparedStatement)8 SQLException (java.sql.SQLException)8 UTC (java.time.ZoneOffset.UTC)8 Calendar (java.util.Calendar)8