// 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.security.dao; import java.util.List; import javax.ejb.Local; import com.cloud.network.security.SecurityGroupVO; import com.cloud.utils.db.GenericDaoBase; import com.cloud.utils.db.SearchBuilder; import com.cloud.utils.db.SearchCriteria; @Local(value={SecurityGroupDao.class}) public class SecurityGroupDaoImpl extends GenericDaoBase<SecurityGroupVO, Long> implements SecurityGroupDao { private SearchBuilder<SecurityGroupVO> AccountIdSearch; private SearchBuilder<SecurityGroupVO> AccountIdNameSearch; private SearchBuilder<SecurityGroupVO> AccountIdNamesSearch; protected SecurityGroupDaoImpl() { AccountIdSearch = createSearchBuilder(); AccountIdSearch.and("accountId", AccountIdSearch.entity().getAccountId(), SearchCriteria.Op.EQ); AccountIdSearch.done(); AccountIdNameSearch = createSearchBuilder(); AccountIdNameSearch.and("accountId", AccountIdNameSearch.entity().getAccountId(), SearchCriteria.Op.EQ); AccountIdNameSearch.and("name", AccountIdNameSearch.entity().getName(), SearchCriteria.Op.EQ); AccountIdNamesSearch = createSearchBuilder(); AccountIdNamesSearch.and("accountId", AccountIdNamesSearch.entity().getAccountId(), SearchCriteria.Op.EQ); AccountIdNamesSearch.and("groupNames", AccountIdNamesSearch.entity().getName(), SearchCriteria.Op.IN); AccountIdNameSearch.done(); } @Override public List<SecurityGroupVO> listByAccountId(long accountId) { SearchCriteria<SecurityGroupVO> sc = AccountIdSearch.create(); sc.setParameters("accountId", accountId); return listBy(sc); } @Override public boolean isNameInUse(Long accountId, Long domainId, String name) { SearchCriteria<SecurityGroupVO> sc = createSearchCriteria(); sc.addAnd("name", SearchCriteria.Op.EQ, name); if (accountId != null) { sc.addAnd("accountId", SearchCriteria.Op.EQ, accountId); } else { sc.addAnd("domainId", SearchCriteria.Op.EQ, domainId); sc.addAnd("accountId", SearchCriteria.Op.NULL); } List<SecurityGroupVO> securityGroups = listBy(sc); return ((securityGroups != null) && !securityGroups.isEmpty()); } @Override public SecurityGroupVO findByAccountAndName(Long accountId, String name) { SearchCriteria<SecurityGroupVO> sc = AccountIdNameSearch.create(); sc.setParameters("accountId", accountId); sc.setParameters("name", name); return findOneIncludingRemovedBy(sc); } @Override public List<SecurityGroupVO> findByAccountAndNames(Long accountId, String... names) { SearchCriteria<SecurityGroupVO> sc = AccountIdNamesSearch.create(); sc.setParameters("accountId", accountId); sc.setParameters("groupNames", (Object [])names); return listBy(sc); } @Override public int removeByAccountId(long accountId) { SearchCriteria sc = AccountIdSearch.create(); sc.setParameters("accountId", accountId); return expunge(sc); } }