List of usage examples for org.hibernate.criterion DetachedCriteria forClass
public static DetachedCriteria forClass(Class clazz)
From source file:com.sjc.cc.instance.service.impl.VmServiceImpl.java
/** * ?//from w w w .j a v a2 s .com */ @SuppressWarnings("unchecked") public boolean expandVm(Long srtApplyedhostAssId) throws Exception, Throwable { TccSrtApplyedhostAss srtApplyedhostAss = vmAssistService.getSrtApplyedhostAss(srtApplyedhostAssId); TccSrt srt = srtApplyedhostAss.getTccSrt(); TccExpdCapacity expdCapacity = vmAssistService.getExpdCapacity(srt.getSrtId()); TccApplyedHostinfo applyedHostinfo = srtApplyedhostAss.getTccApplyedHostinfo(); TccApplyedHostResource applyedHostResource = vmAssistService .getApplyedHostResource(applyedHostinfo.getApplyResourceId()); applyedHostResource.setProcessStatus(BusinessEnvironment.RESOURCE_TYPE_INSTALL); // vmAssistService.updateApplyedHostResource(applyedHostResource); applyedHostResource = vmAssistService.getApplyedHostResource(applyedHostResource.getApplyResourceId()); boolean flag = false; String VirtualType = applyedHostResource.getVirtualType(); // ? // 01.VCVC? if (BusinessEnvironment.VIRTUAL_TYPE_VC.equals(VirtualType)) { flag = capacityMgmtService.upgradeVmVC(srt.getSrtId()); } // 02.CSCS? else if (BusinessEnvironment.VIRTUAL_TYPE_CS.equals(VirtualType)) { flag = capacityMgmtService.upgradeVmCS(srt.getSrtId());// ? } if (!flag) { applyedHostResource.setProcessStatus(BusinessEnvironment.RESOURCE_TYPE_FAIL); // vmAssistService.updateApplyedHostResource(applyedHostResource); return flag; } // ??? TccApplyedHostResource newApplyedHostResource = new TccApplyedHostResource(); BeanUtils.copyProperties(newApplyedHostResource, applyedHostResource); newApplyedHostResource.setCpuCoreCount(expdCapacity.getCpuCoreCount()); newApplyedHostResource.setRamSize(expdCapacity.getRamSize()); if (null != expdCapacity.getStoreSize()) { newApplyedHostResource.setStorageSize(newApplyedHostResource.getStorageSize() == null ? 0 : newApplyedHostResource.getStorageSize() + expdCapacity.getStoreSize()); } else if (null != expdCapacity.getNasStoreSize()) { newApplyedHostResource.setNasStorageSize(newApplyedHostResource.getNasStorageSize() == null ? 0 : newApplyedHostResource.getNasStorageSize() + expdCapacity.getNasStoreSize()); } newApplyedHostResource.setOrginResourceID(applyedHostResource.getOrginResourceID()); newApplyedHostResource.setRunStatusCd(BusinessEnvironment.VM_RUN_STATUS_RUNNING); // ? newApplyedHostResource.setApplyResourceId(null); newApplyedHostResource.setLastuptDttm(null); // ? newApplyedHostResource.setProcessStatus(BusinessEnvironment.RESOURCE_TYPE_SUCCESS); // ?? // ? newApplyedHostResource = vmAssistService.mergeApplyedHostResource(newApplyedHostResource); // ?? applyedHostResource.setRunStatusCd(BusinessEnvironment.RESOURCE_RUNTYPE_EXPDEND);// ? applyedHostResource.setProcessStatus(BusinessEnvironment.RESOURCE_TYPE_SUCCESS);// ? applyedHostResource.setEnableFlg(EnvironmentConstant.DISENABLE); // vmAssistService.updateApplyedHostResource(applyedHostResource); // ???? srtApplyedhostAss.setTccApplyedHostinfo(newApplyedHostResource); vmAssistService.updateSrtApplyedhostAss(srtApplyedhostAss); // ? List<TccProjectAss> newProjectAssList = new ArrayList<TccProjectAss>(); TccProjectAss newTccProjectAss = new TccProjectAss(); // ?? TccProjectAss projectAss = new TccProjectAss(); projectAss.setTccApplyedHostinfo(applyedHostResource); // ***** by zhachaoy ***** DetachedCriteria criteria = DetachedCriteria.forClass(TccProjectAss.class); if (null != projectAss && null != projectAss.getProjectAssId()) { criteria.add(Restrictions.eq("projectAssId", projectAss.getProjectAssId())); } if (null != projectAss && null != projectAss.getTccProjectInfo()) { criteria.add(Restrictions.eq("tccProjectInfo", projectAss.getTccProjectInfo())); } if (null != projectAss && null != projectAss.getTccApplyedHostinfo()) { criteria.add(Restrictions.eq("tccApplyedHostinfo", projectAss.getTccApplyedHostinfo())); } // ?1 criteria.add(Restrictions.or(Restrictions.eq("enableFlg", EnvironmentConstant.ENABLE), Restrictions.isNull("enableFlg"))); List<TccProjectAss> projectAssList = commonDao.findByCriteria(criteria); // ##### by zhachaoy ##### for (TccProjectAss pa : projectAssList) { // ? BeanUtils.copyProperties(newTccProjectAss, pa); newTccProjectAss.setProjectAssId(null); newTccProjectAss.setTccInstanceInfo(null); newTccProjectAss.setTccApplyedHostinfo(newApplyedHostResource); newProjectAssList.add(newTccProjectAss); pa.setEnableFlg(EnvironmentConstant.DISENABLE); } vmAssistService.updateProjectAssList(projectAssList); // ?? this.commonDao.saveOrUpdateAll(newProjectAssList); // List<Object> list = snapshotCategoryService .getVmSnapshotCategory(applyedHostResource.getApplyResourceId().toString()); List<TccSnapshotCfg> tccSnapshotCfgsList = null; List<TccSnapshotHistory> tccSnapshotHistories = null; if (list != null && list.size() > 0) { for (int k = 0; k < list.size(); k++) { if (k == 0) { // ?? tccSnapshotCfgsList = (List<TccSnapshotCfg>) list.get(0); } else if (k == 1) { // ? tccSnapshotHistories = (List<TccSnapshotHistory>) list.get(1); } } // ?resourceId? ?resourceId? if (tccSnapshotCfgsList != null && tccSnapshotCfgsList.size() > 0) { for (TccSnapshotCfg sc : tccSnapshotCfgsList) { sc.setHostId(newApplyedHostResource.getApplyResourceId()); this.commonDao.saveOrUpdate(sc); } } if (tccSnapshotHistories != null && tccSnapshotHistories.size() > 0) { // ??resourceId? ?resourceId? for (TccSnapshotHistory sh : tccSnapshotHistories) { sh.setVmId(newApplyedHostResource.getApplyResourceId()); this.commonDao.saveOrUpdate(sh); } } } LoginUserInfo loginUserInfo = LoginUserInfoHolder.getInstance().getCurrentUser(); logService.saveOperLog("?", "" + loginUserInfo.getEmpName() + "cloudstack" + newApplyedHostResource.getHostNane() + BusinessEnvironment.OPER_RESULT_SUCCESS, newApplyedHostResource, 2); return true; }
From source file:com.thoughtworks.go.server.persistence.MaterialRepository.java
License:Apache License
private DetachedCriteria buildPMRDetachedQuery(List<Long> pipelineIds) { DetachedCriteria criteria = DetachedCriteria.forClass(PipelineMaterialRevision.class); criteria.add(Restrictions.in("pipelineId", pipelineIds)); criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); return criteria; }
From source file:com.thoughtworks.go.server.persistence.MaterialRepository.java
License:Apache License
private DetachedCriteria buildModificationDetachedQuery(List<Criterion> criteria) { DetachedCriteria detachedCriteria = DetachedCriteria.forClass(Modification.class); Disjunction disjunction = Restrictions.disjunction(); detachedCriteria.add(disjunction);//from www .j ava 2s.c o m for (Criterion criterion : criteria) { disjunction.add(criterion); } detachedCriteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY); return detachedCriteria; }
From source file:com.thoughtworks.go.server.persistence.MaterialRepository.java
License:Apache License
public MaterialInstance findMaterialInstance(Material material) { String cacheKey = materialKey(material); MaterialInstance materialInstance = (MaterialInstance) goCache.get(cacheKey); if (materialInstance == null) { synchronized (cacheKey) { materialInstance = (MaterialInstance) goCache.get(cacheKey); if (materialInstance == null) { DetachedCriteria hibernateCriteria = DetachedCriteria.forClass(material.getInstanceType()); for (Map.Entry<String, Object> property : material.getSqlCriteria().entrySet()) { if (!property.getKey().equals(AbstractMaterial.SQL_CRITERIA_TYPE)) {//type is polymorphic mapping discriminator if (property.getValue() == null) { hibernateCriteria.add(isNull(property.getKey())); } else { hibernateCriteria.add(eq(property.getKey(), property.getValue())); }/* w ww .j a v a 2 s .c o m*/ } } materialInstance = (MaterialInstance) firstResult(hibernateCriteria); if (materialInstance != null) { goCache.put(cacheKey, materialInstance); } } } } return materialInstance;//TODO: clone me, caller may mutate }
From source file:com.thoughtworks.go.server.persistence.MaterialRepository.java
License:Apache License
public MaterialInstance findMaterialInstance(MaterialConfig materialConfig) { String cacheKey = materialKey(materialConfig.getFingerprint()); MaterialInstance materialInstance = (MaterialInstance) goCache.get(cacheKey); if (materialInstance == null) { synchronized (cacheKey) { materialInstance = (MaterialInstance) goCache.get(cacheKey); if (materialInstance == null) { DetachedCriteria hibernateCriteria = DetachedCriteria .forClass(materialConfigConverter.getInstanceType(materialConfig)); for (Map.Entry<String, Object> property : materialConfig.getSqlCriteria().entrySet()) { if (!property.getKey().equals(AbstractMaterial.SQL_CRITERIA_TYPE)) { //type is polymorphic mapping discriminator if (property.getValue() == null) { hibernateCriteria.add(isNull(property.getKey())); } else { hibernateCriteria.add(eq(property.getKey(), property.getValue())); }//from w w w.java2 s . c o m } } materialInstance = (MaterialInstance) firstResult(hibernateCriteria); if (materialInstance != null) { goCache.put(cacheKey, materialInstance); } } } } return materialInstance;//TODO: clone me, caller may mutate }
From source file:com.thoughtworks.go.server.persistence.MaterialRepository.java
License:Apache License
private void checkAndRemoveDuplicates(MaterialInstance materialInstance, List<Modification> newChanges, ArrayList<Modification> list) { if (!new SystemEnvironment().get(SystemEnvironment.CHECK_AND_REMOVE_DUPLICATE_MODIFICATIONS)) { return;// ww w.j a va 2 s. c om } DetachedCriteria criteria = DetachedCriteria.forClass(Modification.class); criteria.setProjection(Projections.projectionList().add(Projections.property("revision"))); criteria.add(Restrictions.eq("materialInstance.id", materialInstance.getId())); ArrayList<String> revisions = new ArrayList<>(); for (Modification modification : newChanges) { revisions.add(modification.getRevision()); } criteria.add(Restrictions.in("revision", revisions)); List<String> matchingRevisionsFromDb = (List<String>) getHibernateTemplate().findByCriteria(criteria); if (!matchingRevisionsFromDb.isEmpty()) { for (final String revision : matchingRevisionsFromDb) { Modification modification = list.stream().filter(item -> item.getRevision().equals(revision)) .findFirst().orElse(null); list.remove(modification); } } if (!newChanges.isEmpty() && list.isEmpty()) { LOGGER.debug("All modifications already exist in db [{}]", revisions); } if (!matchingRevisionsFromDb.isEmpty()) { LOGGER.info("Saving revisions for material [{}] after removing the following duplicates {}", materialInstance.toOldMaterial(null, null, null).getLongDescription(), matchingRevisionsFromDb); } }
From source file:com.tysanclan.site.projectewok.entities.dao.hibernate.ConversationDAOImpl.java
License:Open Source License
@Override protected Criteria createCriteria(SearchFilter<Conversation> _filter) { ConversationFilter filter = (ConversationFilter) _filter; Criteria crit = getSession().createCriteria(Conversation.class); if (filter.isSortByLastResponse()) { filter.addOrderBy("id", false); filter.addOrderBy("lastResponse", false); }/*from w w w . j a v a2s .c o m*/ if (!filter.getParticipants().isEmpty()) { for (User participant : filter.getParticipants()) { DetachedCriteria dc = DetachedCriteria.forClass(ConversationParticipation.class); dc.add(Restrictions.eq("user", participant)); dc.setProjection(Projections.property("conversation")); crit.add(Subqueries.propertyIn("id", dc)); } } return crit; }
From source file:com.tysanclan.site.projectewok.entities.dao.hibernate.InactivityNotificationDAOImpl.java
License:Open Source License
@Override public List<Long> getUnnotifiedInactiveUsers() { Criteria criteria = getSession().createCriteria(User.class); DetachedCriteria dc = DetachedCriteria.forClass(InactivityNotification.class); dc.setProjection(Projections.property("user")); criteria.add(Subqueries.propertyNotIn("id", dc)); Disjunction d = Restrictions.disjunction(); d.add(getTrialMemberInactivityCriterion()); d.add(getVacationMemberInactivityCriterion()); d.add(getRetiredMemberInactivityCriterion()); d.add(getRegularMemberInactivityCriterion()); criteria.add(d);/*w w w . j av a2 s. c o m*/ criteria.setProjection(Projections.property("id")); List<Long> ids = listOf(criteria); return ids; }
From source file:com.ut.tekir.contact.ContactBrowseBean.java
License:LGPL
@Override public DetachedCriteria buildCriteria() { DetachedCriteria crit = DetachedCriteria.forClass(Contact.class); crit.setProjection(Projections.distinct(Projections.projectionList().add(Projections.property("id"), "id") .add(Projections.property("code"), "code").add(Projections.property("name"), "name") .add(Projections.property("fullname"), "fullname").add(Projections.property("ssn"), "ssn") .add(Projections.property("company"), "company").add(Projections.property("taxNumber"), "taxNumber") .add(Projections.property("taxOffice"), "taxOffice").add(Projections.property("title"), "title") .add(Projections.property("representative"), "representative") .add(Projections.property("info"), "info").add(Projections.property("exCode1"), "exCode1") .add(Projections.property("exCode2"), "exCode2").add(Projections.property("allType"), "allType") .add(Projections.property("customerType"), "customerType") .add(Projections.property("providerType"), "providerType") .add(Projections.property("agentType"), "agentType") .add(Projections.property("personnelType"), "personnelType") .add(Projections.property("branchType"), "branchType") .add(Projections.property("contactType"), "contactType") .add(Projections.property("bankType"), "bankType") .add(Projections.property("relatedType"), "relatedType") .add(Projections.property("foundationType"), "foundationType"))); crit.setResultTransformer(Transformers.aliasToBean(ContactModel.class)); if (filterModel.getCode() != null && filterModel.getCode().length() > 0) { crit.add(Restrictions.ilike("this.code", filterModel.getCode(), MatchMode.START)); }//from w w w .jav a 2s. co m if (filterModel.getFullname() != null && filterModel.getFullname().length() > 0) { crit.add(Restrictions.ilike("this.fullname", filterModel.getFullname(), MatchMode.ANYWHERE)); } if (filterModel.getCompany() != null && filterModel.getCompany().length() > 0) { crit.add(Restrictions.ilike("this.company", filterModel.getCompany(), MatchMode.START)); } if (filterModel.getSsn() != null && filterModel.getSsn().length() > 0) { crit.add(Restrictions.ilike("this.ssn", filterModel.getSsn(), MatchMode.START)); } if (filterModel.getTaxNumber() != null && filterModel.getTaxNumber().length() > 0) { crit.add(Restrictions.ilike("this.taxNumber", filterModel.getTaxNumber(), MatchMode.START)); } if (filterModel.getRepresentative() != null && filterModel.getRepresentative().length() > 0) { crit.add(Restrictions.ilike("this.representative", filterModel.getRepresentative(), MatchMode.START)); } if (filterModel.getExCode1() != null && filterModel.getExCode1().length() > 0) { crit.add(Restrictions.ilike("this.exCode1", filterModel.getExCode1(), MatchMode.START)); } if (filterModel.getExCode2() != null && filterModel.getExCode2().length() > 0) { crit.add(Restrictions.ilike("this.exCode2", filterModel.getExCode2(), MatchMode.START)); } if (filterModel.getCategory() != null) { crit.add(Restrictions.eq("this.category", filterModel.getCategory())); } if (filterModel.getOrganization() != null) { crit.add(Restrictions.eq("this.organization", filterModel.getOrganization())); } if (filterModel.getCompanyType() != null && !filterModel.getCompanyType().equals("All")) { if (filterModel.getCompanyType().equals("Person")) { crit.add(Restrictions.eq("this.person", Boolean.TRUE)); } else crit.add(Restrictions.eq("this.person", Boolean.FALSE)); } if (filterModel.getType() != null && filterModel.getType() != ContactType.All) { crit.add(Restrictions.eq("this." + filterModel.getType().toString().toLowerCase() + "Type", Boolean.TRUE)); } if (filterModel.getCountry() != null) { crit.createAlias("this.addressList", "addressList", CriteriaSpecification.INNER_JOIN); crit.add(Restrictions.eq("addressList.address.country", filterModel.getCountry())); if (filterModel.getCity1() != null) { crit.add(Restrictions.eq("addressList.city", filterModel.getCity1())); } } //FIXME: bu kontrol nasl olmal? if (hasRegionRestriction()) { if (activeUser.getContact() != null && activeUser.getContact().getOrganization() != null && activeUser.getContact().getOrganization() != null) { crit.add(Restrictions.or( Restrictions.eq("this.organization.id", activeUser.getContact().getOrganization().getId()), Restrictions.eq("this.isPublic", Boolean.TRUE))); } } crit.addOrder(Order.desc("this.code")); return crit; }
From source file:com.ut.tekir.contact.ContactStatusBean.java
License:LGPL
@SuppressWarnings("unchecked") public List getResultList(Long contactId) { log.debug("Cari durum sorgusu ekiliyor"); DetachedCriteria crit = DetachedCriteria.forClass(FinanceTxn.class); crit.add(Restrictions.eq("active", true)); crit.add(Restrictions.eq("contact.id", contactId)); /*/*from w ww.ja va2 s .com*/ crit.setProjection( Projections.sum("amount")) .setProjection( Projections.groupProperty("contact")) .setProjection( Projections.property("contact")); */ HibernateSessionProxy session = (HibernateSessionProxy) entityManager.getDelegate(); Criteria ecrit = crit.getExecutableCriteria(session); log.debug("Cari durum sorgusu ekiliyor"); //ecrit.setMaxResults( 100 ); return ecrit.list(); }