<commit_before>package org.ovirt.engine.core.dao.network;

import org.ovirt.engine.core.common.businessentities.network.NetworkQoS;
import org.ovirt.engine.core.compat.Guid;
import org.ovirt.engine.core.dao.DefaultGenericDaoDbFacade;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

public class NetworkQoSDaoFacadeImpl extends DefaultGenericDaoDbFacade<NetworkQoS, Guid> implements NetworkQoSDao {

    protected final RowMapper<NetworkQoS> mapper = createEntityRowMapper();

    public NetworkQoSDaoFacadeImpl(){
        super("NetworkQos");
    }

    private static Integer getIntegerOrNull(ResultSet rs, String columnName) throws SQLException {
        String string = rs.getString(columnName);
        return string == null ? null : Integer.parseInt(string);
    }

    @Override
    protected MapSqlParameterSource createIdParameterMapper(Guid guid) {
        return getCustomMapSqlParameterSource()
                .addValue("id", guid);
    }

    @Override
    protected RowMapper<NetworkQoS> createEntityRowMapper() {
        return new RowMapper<NetworkQoS>() {
            @Override
            public NetworkQoS mapRow(ResultSet rs, int rowNum)
                    throws SQLException {
                NetworkQoS entity = new NetworkQoS();
                entity.setId(Guid.createGuidFromString(rs.getString("id")));
                entity.setName(rs.getString("name"));
                entity.setStoragePoolId(Guid.createGuidFromString(rs.getString("storage_pool_id")));
                entity.setInboundAverage(getIntegerOrNull(rs, "inbound_average"));
                entity.setInboundPeak(getIntegerOrNull(rs, "inbound_peak"));
                entity.setInboundBurst(getIntegerOrNull(rs, "inbound_burst"));
                entity.setOutboundAverage(getIntegerOrNull(rs, "outbound_average"));
                entity.setOutboundPeak(getIntegerOrNull(rs, "outbound_peak"));
                entity.setOutboundBurst(getIntegerOrNull(rs, "outbound_burst"));
                return entity;
            }
        };
    }

    @Override
    public List<NetworkQoS> getAllForStoragePoolId(Guid storagePoolId) {
        MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource()
                .addValue("storage_pool_id", storagePoolId.getUuid());
        return getCallsHandler().executeReadList("GetAllNetworkQosForStoragePool", mapper, parameterSource);
    }

    @Override
    protected MapSqlParameterSource createFullParametersMapper(NetworkQoS networkQoS) {
        return getCustomMapSqlParameterSource()
                .addValue("id", networkQoS.getId())
                .addValue("name", networkQoS.getName())
                .addValue("storage_pool_id", networkQoS.getStoragePoolId())
                .addValue("inbound_average", networkQoS.getInboundAverage())<commit_msg>core: Fix optimization of NetworkQoSDaoFacadeImpl<commit_after>package org.ovirt.engine.core.dao.network;

import org.ovirt.engine.core.common.businessentities.network.NetworkQoS;
import org.ovirt.engine.core.compat.Guid;
import org.ovirt.engine.core.dao.DefaultGenericDaoDbFacade;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

public class NetworkQoSDaoFacadeImpl extends DefaultGenericDaoDbFacade<NetworkQoS, Guid> implements NetworkQoSDao {

    protected final RowMapper<NetworkQoS> mapper = createEntityRowMapper();

    public NetworkQoSDaoFacadeImpl(){
        super("NetworkQos");
    }

    private static Integer getIntegerOrNull(ResultSet rs, String columnName) throws SQLException {
        int i = rs.getInt(columnName);
        return rs.wasNull() ? null : i;
    }

    @Override
    protected MapSqlParameterSource createIdParameterMapper(Guid guid) {
        return getCustomMapSqlParameterSource()
                .addValue("id", guid);
    }

    @Override
    protected RowMapper<NetworkQoS> createEntityRowMapper() {
        return new RowMapper<NetworkQoS>() {
            @Override
            public NetworkQoS mapRow(ResultSet rs, int rowNum)
                    throws SQLException {
                NetworkQoS entity = new NetworkQoS();
                entity.setId(getGuid(rs, "id"));
                entity.setName(rs.getString("name"));
                entity.setStoragePoolId(getGuid(rs, "storage_pool_id"));
                entity.setInboundAverage(getIntegerOrNull(rs, "inbound_average"));
                entity.setInboundPeak(getIntegerOrNull(rs, "inbound_peak"));
                entity.setInboundBurst(getIntegerOrNull(rs, "inbound_burst"));
                entity.setOutboundAverage(getIntegerOrNull(rs, "outbound_average"));
                entity.setOutboundPeak(getIntegerOrNull(rs, "outbound_peak"));
                entity.setOutboundBurst(getIntegerOrNull(rs, "outbound_burst"));
                return entity;
            }
        };
    }

    @Override
    public List<NetworkQoS> getAllForStoragePoolId(Guid storagePoolId) {
        MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource()
                .addValue("storage_pool_id", storagePoolId.getUuid());
        return getCallsHandler().executeReadList("GetAllNetworkQosForStoragePool", mapper, parameterSource);
    }

    @Override
    protected MapSqlParameterSource createFullParametersMapper(NetworkQoS networkQoS) {
        return getCustomMapSqlParameterSource()
                .addValue("id", networkQoS.getId())
                .addValue("name", networkQoS.getName())
                .addValue("storage_pool_id", networkQoS.getStoragePoolId())
                .addValue("inbound_average", networkQoS.getInboundAverage())
{'fraction_non_alphanumeric': 0.09557069846678024, 'fraction_numerical': 0.0, 'mean_word_length': 3.2760378732702113, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4945924', 'n_tokens_mistral': 1673, 'n_tokens_neox': 1580, 'n_words': 256}