Search in sources :

Example 1 with StoragePoolTagVO

use of com.cloud.storage.StoragePoolTagVO in project cloudstack by apache.

the class StoragePoolTagsDaoImpl method getStoragePoolTags.

@Override
public List<String> getStoragePoolTags(long poolId) {
    SearchCriteria<StoragePoolTagVO> sc = StoragePoolSearch.create();
    sc.setParameters("poolId", poolId);
    List<StoragePoolTagVO> results = search(sc, null);
    List<String> storagePoolTags = new ArrayList<String>(results.size());
    for (StoragePoolTagVO result : results) {
        storagePoolTags.add(result.getTag());
    }
    return storagePoolTags;
}
Also used : StoragePoolTagVO(com.cloud.storage.StoragePoolTagVO) ArrayList(java.util.ArrayList)

Example 2 with StoragePoolTagVO

use of com.cloud.storage.StoragePoolTagVO in project cloudstack by apache.

the class StoragePoolTagsDaoImpl method deleteTags.

@Override
public void deleteTags(long poolId) {
    TransactionLegacy txn = TransactionLegacy.currentTxn();
    txn.start();
    SearchCriteria<StoragePoolTagVO> sc = StoragePoolSearch.create();
    sc.setParameters("poolId", poolId);
    expunge(sc);
    txn.commit();
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) StoragePoolTagVO(com.cloud.storage.StoragePoolTagVO)

Example 3 with StoragePoolTagVO

use of com.cloud.storage.StoragePoolTagVO in project cloudstack by apache.

the class QueryManagerImpl method searchForStorageTagsInternal.

private Pair<List<StoragePoolTagVO>, Integer> searchForStorageTagsInternal(ListStorageTagsCmd cmd) {
    Filter searchFilter = new Filter(StoragePoolTagVO.class, "id", Boolean.TRUE, null, null);
    SearchBuilder<StoragePoolTagVO> sb = _storageTagDao.createSearchBuilder();
    // select distinct
    sb.select(null, Func.DISTINCT, sb.entity().getId());
    SearchCriteria<StoragePoolTagVO> sc = sb.create();
    // search storage tag details by ids
    Pair<List<StoragePoolTagVO>, Integer> uniqueTagPair = _storageTagDao.searchAndCount(sc, searchFilter);
    Integer count = uniqueTagPair.second();
    if (count.intValue() == 0) {
        return uniqueTagPair;
    }
    List<StoragePoolTagVO> uniqueTags = uniqueTagPair.first();
    Long[] vrIds = new Long[uniqueTags.size()];
    int i = 0;
    for (StoragePoolTagVO v : uniqueTags) {
        vrIds[i++] = v.getId();
    }
    List<StoragePoolTagVO> vrs = _storageTagDao.searchByIds(vrIds);
    return new Pair<List<StoragePoolTagVO>, Integer>(vrs, count);
}
Also used : TemplateFilter(com.cloud.template.VirtualMachineTemplate.TemplateFilter) Filter(com.cloud.utils.db.Filter) StoragePoolTagVO(com.cloud.storage.StoragePoolTagVO) ArrayList(java.util.ArrayList) List(java.util.List) Pair(com.cloud.utils.Pair)

Example 4 with StoragePoolTagVO

use of com.cloud.storage.StoragePoolTagVO in project cloudstack by apache.

the class StoragePoolTagsDaoImpl method persist.

@Override
public void persist(long poolId, List<String> storagePoolTags) {
    TransactionLegacy txn = TransactionLegacy.currentTxn();
    txn.start();
    SearchCriteria<StoragePoolTagVO> sc = StoragePoolSearch.create();
    sc.setParameters("poolId", poolId);
    expunge(sc);
    for (String tag : storagePoolTags) {
        tag = tag.trim();
        if (tag.length() > 0) {
            StoragePoolTagVO vo = new StoragePoolTagVO(poolId, tag);
            persist(vo);
        }
    }
    txn.commit();
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) StoragePoolTagVO(com.cloud.storage.StoragePoolTagVO)

Aggregations

StoragePoolTagVO (com.cloud.storage.StoragePoolTagVO)4 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)2 ArrayList (java.util.ArrayList)2 TemplateFilter (com.cloud.template.VirtualMachineTemplate.TemplateFilter)1 Pair (com.cloud.utils.Pair)1 Filter (com.cloud.utils.db.Filter)1 List (java.util.List)1