// Copyright 2012 Citrix Systems, Inc. Licensed under the // Apache License, Version 2.0 (the "License"); you may not use this // file except in compliance with the License. Citrix Systems, Inc. // reserves all rights not expressly granted by the License. // You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // Automatically generated by addcopyright.py at 04/03/2012 package com.cloud.network.dao; import java.util.List; import com.cloud.utils.db.Attribute; import com.cloud.utils.db.GenericDao; import com.cloud.utils.db.GenericDaoBase; import com.cloud.utils.db.GenericSearchBuilder; import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchCriteria; import com.cloud.utils.db.SearchCriteria.Op; import com.cloud.utils.db.UpdateBuilder; public class NetworkOpDaoImpl extends GenericDaoBase<NetworkOpVO, Long> implements GenericDao<NetworkOpVO, Long> { protected final SearchBuilder<NetworkOpVO> AllFieldsSearch; protected final GenericSearchBuilder<NetworkOpVO, Integer> ActiveNicsSearch; protected final GenericSearchBuilder<NetworkOpVO, Long> GarbageCollectSearch; protected final Attribute _activeNicsAttribute; protected NetworkOpDaoImpl() { super(); ActiveNicsSearch = createSearchBuilder(Integer.class); ActiveNicsSearch.selectField(ActiveNicsSearch.entity().getActiveNicsCount()); ActiveNicsSearch.and("network", ActiveNicsSearch.entity().getId(), Op.EQ); ActiveNicsSearch.done(); AllFieldsSearch = createSearchBuilder(); AllFieldsSearch.and("network", AllFieldsSearch.entity().getId(), Op.EQ); AllFieldsSearch.done(); GarbageCollectSearch = createSearchBuilder(Long.class); GarbageCollectSearch.selectField(GarbageCollectSearch.entity().getId()); GarbageCollectSearch.and("activenics", GarbageCollectSearch.entity().getActiveNicsCount(), Op.EQ); GarbageCollectSearch.and("gc", GarbageCollectSearch.entity().isGarbageCollected(), Op.EQ); GarbageCollectSearch.and("check", GarbageCollectSearch.entity().isCheckForGc(), Op.EQ); GarbageCollectSearch.done(); _activeNicsAttribute = _allAttributes.get("activeNicsCount"); assert _activeNicsAttribute != null : "Cannot find activeNicsCount"; } public List<Long> getNetworksToGarbageCollect() { SearchCriteria<Long> sc = GarbageCollectSearch.create(); sc.setParameters("activenics", 0); sc.setParameters("gc", true); sc.setParameters("check", true); return customSearch(sc, null); } public int getActiveNics(long networkId) { SearchCriteria<Integer> sc = ActiveNicsSearch.create(); sc.setParameters("network", networkId); return customSearch(sc, null).get(0); } public void changeActiveNicsBy(long networkId, int count) { SearchCriteria<NetworkOpVO> sc = AllFieldsSearch.create(); sc.setParameters("network", networkId); NetworkOpVO vo = createForUpdate(); UpdateBuilder builder = getUpdateBuilder(vo); builder.incr(_activeNicsAttribute, count); update(builder, sc, null); } public void setCheckForGc(long networkId) { NetworkOpVO vo = createForUpdate(); vo.setCheckForGc(true); update(networkId, vo); } public void clearCheckForGc(long networkId) { NetworkOpVO vo = createForUpdate(); vo.setCheckForGc(false); update(networkId, vo); } }