Search in sources :

Example 86 with MapSqlParameterSource

use of org.springframework.jdbc.core.namedparam.MapSqlParameterSource in project ovirt-engine by oVirt.

the class TagDaoImpl method attachVmToTag.

@Override
public void attachVmToTag(TagsVmMap tagVmMap) {
    MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource().addValue("tag_id", tagVmMap.getTagId()).addValue("vm_id", tagVmMap.getVmId()).addValue("DefaultDisplayType", tagVmMap.getDefaultDisplayType());
    getCallsHandler().executeModification("Inserttags_vm_map", parameterSource);
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource)

Example 87 with MapSqlParameterSource

use of org.springframework.jdbc.core.namedparam.MapSqlParameterSource in project ovirt-engine by oVirt.

the class QuotaDaoImpl method getAllRelevantQuotasForCluster.

@Override
public List<Quota> getAllRelevantQuotasForCluster(Guid clusterId, long engineSessionSeqId, boolean isFiltered) {
    MapSqlParameterSource quotaParameterSource = getCustomMapSqlParameterSource();
    quotaParameterSource.addValue("cluster_id", clusterId).addValue("engine_session_seq_id", engineSessionSeqId).addValue("is_filtered", isFiltered);
    return getCallsHandler().executeReadList("getAllThinQuotasByClusterId", getQuotaMetaDataFromResultSet(), quotaParameterSource);
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource)

Example 88 with MapSqlParameterSource

use of org.springframework.jdbc.core.namedparam.MapSqlParameterSource in project ovirt-engine by oVirt.

the class QuotaDaoImpl method getAllQuotaIncludingConsumption.

/**
 * Get all the full quotas. Including consumption data. This call is very heavy and should be used really and with
 * caution. It was created to support cache initialization
 *
 * @return all quota in DB (including consumption calculation)
 */
@Override
public List<Quota> getAllQuotaIncludingConsumption() {
    MapSqlParameterSource parameterSource = new MapSqlParameterSource();
    // get thin quota (only basic quota meta data)
    List<Quota> allThinQuota = getCallsHandler().executeReadList("getAllThinQuota", getQuotaMetaDataFromResultSet(), parameterSource);
    if (!allThinQuota.isEmpty()) {
        Map<Guid, Quota> allQuotaMap = new HashMap<>();
        for (Quota quota : allThinQuota) {
            allQuotaMap.put(quota.getId(), quota);
        }
        List<QuotaStorage> quotaStorageList = getAllQuotaStorageIncludingConsumption();
        List<QuotaCluster> quotaClusterList = getAllQuotaClusterIncludingConsumption();
        for (QuotaStorage quotaStorage : quotaStorageList) {
            Quota quota = allQuotaMap.get(quotaStorage.getQuotaId());
            if (quota != null) {
                if (quotaStorage.getStorageId() == null || quotaStorage.getStorageId().equals(Guid.Empty)) {
                    quota.setGlobalQuotaStorage(quotaStorage);
                } else {
                    if (quota.getQuotaStorages() == null) {
                        quota.setQuotaStorages(new ArrayList<>());
                    }
                    quota.getQuotaStorages().add(quotaStorage);
                }
            }
        }
        for (QuotaCluster quotaCluster : quotaClusterList) {
            Quota quota = allQuotaMap.get(quotaCluster.getQuotaId());
            if (quota != null) {
                if (quotaCluster.getClusterId() == null || quotaCluster.getClusterId().equals(Guid.Empty)) {
                    quota.setGlobalQuotaCluster(quotaCluster);
                } else {
                    if (quota.getQuotaClusters() == null) {
                        quota.setQuotaClusters(new ArrayList<>());
                    }
                    quota.getQuotaClusters().add(quotaCluster);
                }
            }
        }
    }
    // The thin quota were all filled
    return allThinQuota;
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) QuotaStorage(org.ovirt.engine.core.common.businessentities.QuotaStorage) Quota(org.ovirt.engine.core.common.businessentities.Quota) HashMap(java.util.HashMap) QuotaCluster(org.ovirt.engine.core.common.businessentities.QuotaCluster) Guid(org.ovirt.engine.core.compat.Guid)

Example 89 with MapSqlParameterSource

use of org.springframework.jdbc.core.namedparam.MapSqlParameterSource in project ovirt-engine by oVirt.

the class RepoFileMetaDataDaoImpl method addRepoFileMap.

@Override
public void addRepoFileMap(RepoImage map) {
    MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource().addValue("repo_domain_id", map.getRepoDomainId()).addValue("repo_image_id", map.getRepoImageId()).addValue("repo_image_name", map.getRepoImageName()).addValue("size", map.getSize()).addValue("date_created", map.getDateCreated()).addValue("last_refreshed", map.getLastRefreshed()).addValue("file_type", map.getFileType().getValue());
    getCallsHandler().executeModification("InsertRepo_domain_file_meta_data", parameterSource);
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource)

Example 90 with MapSqlParameterSource

use of org.springframework.jdbc.core.namedparam.MapSqlParameterSource in project ovirt-engine by oVirt.

the class RepoFileMetaDataDaoImpl method removeRepoDomainFileList.

@Override
public void removeRepoDomainFileList(Guid id, ImageFileType fileType) {
    MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource().addValue("storage_domain_id", id);
    if (fileType == null || fileType == ImageFileType.All) {
        parameterSource.addValue("file_type", null);
    } else {
        parameterSource.addValue("file_type", fileType.getValue());
    }
    getCallsHandler().executeModification("DeleteRepo_domain_file_list", parameterSource);
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource)

Aggregations

MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)505 NamedParameterJdbcTemplate (org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate)82 SqlParameterSource (org.springframework.jdbc.core.namedparam.SqlParameterSource)63 Test (org.junit.jupiter.api.Test)48 ArrayList (java.util.ArrayList)36 EmptyResultDataAccessException (org.springframework.dao.EmptyResultDataAccessException)34 ResultSet (java.sql.ResultSet)33 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)32 List (java.util.List)30 HashMap (java.util.HashMap)29 SQLException (java.sql.SQLException)25 Guid (org.ovirt.engine.core.compat.Guid)25 Collectors (java.util.stream.Collectors)16 CustomMapSqlParameterSource (org.ovirt.engine.core.dal.dbbroker.CustomMapSqlParameterSource)16 Transactional (org.springframework.transaction.annotation.Transactional)16 java.util (java.util)13 Component (org.springframework.stereotype.Component)13 Map (java.util.Map)12 RowMapper (org.springframework.jdbc.core.RowMapper)11 Named (javax.inject.Named)10