Search in sources :

Example 1 with ERROR_CODE_INSERT_ATTRIBUTE

use of org.wso2.carbon.identity.configuration.mgt.core.constant.ConfigurationConstants.ErrorMessages.ERROR_CODE_INSERT_ATTRIBUTE 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)

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