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