Search in sources :

Example 1 with INSERT_OR_UPDATE_ATTRIBUTE_MYSQL

use of org.wso2.carbon.identity.configuration.mgt.core.constant.SQLConstants.INSERT_OR_UPDATE_ATTRIBUTE_MYSQL in project carbon-identity-framework by wso2.

the class ConfigurationDAOImpl method replaceAttribute.

/**
 * {@inheritDoc}
 */
@Override
public void replaceAttribute(String attributeId, String resourceId, Attribute attribute) throws ConfigurationManagementException {
    JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();
    try {
        jdbcTemplate.withTransaction(template -> {
            String query = INSERT_OR_UPDATE_ATTRIBUTE_MYSQL;
            if (isH2DB()) {
                query = INSERT_OR_UPDATE_ATTRIBUTE_H2;
            } else if (isPostgreSQLDB()) {
                query = INSERT_OR_UPDATE_ATTRIBUTE_POSTGRESQL;
            } else if (isMSSqlDB() || isDB2DB()) {
                query = INSERT_OR_UPDATE_ATTRIBUTE_MSSQL_OR_DB2;
            } else if (isOracleDB()) {
                query = INSERT_OR_UPDATE_ATTRIBUTE_ORACLE;
            }
            template.executeUpdate(query, 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_REPLACE_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)

Aggregations

Timestamp (java.sql.Timestamp)1 Date (java.util.Date)1 JdbcTemplate (org.wso2.carbon.database.utils.jdbc.JdbcTemplate)1 TransactionException (org.wso2.carbon.database.utils.jdbc.exceptions.TransactionException)1