List of usage examples for org.hibernate Criteria createCriteria
public Criteria createCriteria(String associationPath) throws HibernateException;
From source file:com.npower.dm.hibernate.management.ProvisionJobManagementBeanImpl.java
License:Open Source License
public List<ProvisionJob> findJobs(String jobType, String jobState, Device device) throws DMException { try {/* w ww . j ava2s . c om*/ Session session = this.getHibernateSession(); Criteria mainCriteria = session.createCriteria(ProvisionRequest.class); mainCriteria.add(Expression.eq("jobMode", ProvisionJob.JOB_MODE_DM)); mainCriteria.add(Expression.eq("jobType", jobType)); //mainCriteria.add(Expression.eq("state", jobState)); mainCriteria.addOrder(Order.asc("scheduledTime")); mainCriteria.addOrder(Order.asc("ID")); Criteria elementCriteria = mainCriteria.createCriteria("provisionElements"); // Set status criteria Criteria statusCriteria = elementCriteria.createCriteria("deviceProvReqs"); statusCriteria.add(Expression.eq("state", jobState)); statusCriteria.add(Expression.eq("device", device)); // Set search by device //Criteria groupCriteria = elementCriteria.createCriteria("deviceGroup"); //Criteria deviceCriteria = groupCriteria.createCriteria("devicesForDeviceGroup"); //deviceCriteria.add(Expression.eq("device", device)); return mainCriteria.list(); } catch (HibernateException ex) { throw new DMException(ex); } }
From source file:com.npower.dm.hibernate.management.ProvisionJobManagementBeanImpl.java
License:Open Source License
public List<ProvisionJob> findJobsQueued(String jobType, Device device, boolean scheduled) throws DMException { try {// w w w . jav a2s. c o m Session session = this.getHibernateSession(); Criteria mainCriteria = session.createCriteria(ProvisionRequest.class); mainCriteria.add(Expression.eq("jobMode", ProvisionJob.JOB_MODE_DM)); mainCriteria.add(Expression.eq("jobType", jobType)); mainCriteria.add(Expression.eq("state", ProvisionJob.JOB_STATE_APPLIED)); if (scheduled) { mainCriteria.add(Expression.le("scheduledTime", new Date())); } mainCriteria.addOrder(Order.asc("scheduledTime")); mainCriteria.addOrder(Order.asc("ID")); Criteria elementCriteria = mainCriteria.createCriteria("provisionElements"); Criteria deviceStatus = elementCriteria.createCriteria("deviceProvReqs"); deviceStatus.add(Expression.eq("device", device)); // DeviceJobStatus are READY, NOTIFIED or Doing Disjunction states = Expression.disjunction(); states.add(Expression.eq("state", ProvisionJobStatus.DEVICE_JOB_STATE_READY)); states.add(Expression.eq("state", ProvisionJobStatus.DEVICE_JOB_STATE_NOTIFIED)); states.add(Expression.eq("state", ProvisionJobStatus.DEVICE_JOB_STATE_DOING)); deviceStatus.add(states); // Set search by Carrier //Criteria carrierCrit = elementCriteria.createCriteria("carrier"); //carrierCrit.add(Expression.eq("ID", new Long(carrier.getID()))); // Set search by device Criteria groupCriteria = elementCriteria.createCriteria("deviceGroup"); Criteria deviceCriteria = groupCriteria.createCriteria("devicesForDeviceGroup"); deviceCriteria.add(Expression.eq("device", device)); return mainCriteria.list(); } catch (HibernateException ex) { throw new DMException(ex); } }
From source file:com.npower.dm.hibernate.management.ProvisionJobManagementBeanImpl.java
License:Open Source License
public List<ProvisionJob> findJobsQueued(Device device, boolean scheduled) throws DMException { try {/* w w w. java2 s .co m*/ Session session = this.getHibernateSession(); Criteria mainCriteria = session.createCriteria(ProvisionRequest.class); mainCriteria.add(Expression.eq("jobMode", ProvisionJob.JOB_MODE_DM)); mainCriteria.add(Expression.eq("state", ProvisionJob.JOB_STATE_APPLIED)); if (scheduled) { mainCriteria.add(Expression.le("scheduledTime", new Date())); } mainCriteria.addOrder(Order.asc("scheduledTime")); mainCriteria.addOrder(Order.asc("ID")); Criteria elementCriteria = mainCriteria.createCriteria("provisionElements"); Criteria deviceStatus = elementCriteria.createCriteria("deviceProvReqs"); deviceStatus.add(Expression.eq("device", device)); // DeviceJobStatus are READY, NOTIFIED or Doing Disjunction states = Expression.disjunction(); states.add(Expression.eq("state", ProvisionJobStatus.DEVICE_JOB_STATE_READY)); states.add(Expression.eq("state", ProvisionJobStatus.DEVICE_JOB_STATE_NOTIFIED)); states.add(Expression.eq("state", ProvisionJobStatus.DEVICE_JOB_STATE_DOING)); deviceStatus.add(states); // Set search by Carrier //Criteria carrierCrit = elementCriteria.createCriteria("carrier"); //carrierCrit.add(Expression.eq("ID", new Long(carrier.getID()))); // Set search by device Criteria groupCriteria = elementCriteria.createCriteria("deviceGroup"); Criteria deviceCriteria = groupCriteria.createCriteria("devicesForDeviceGroup"); deviceCriteria.add(Expression.eq("device", device)); return mainCriteria.list(); } catch (HibernateException ex) { throw new DMException(ex); } }
From source file:com.npower.dm.hibernate.management.ProvisionJobManagementBeanImpl.java
License:Open Source License
public List<ProvisionJob> findJobsQueued(boolean scheduled) throws DMException { try {//w ww .j a va 2 s.c o m Session session = this.getHibernateSession(); Criteria mainCriteria = session.createCriteria(ProvisionRequest.class); mainCriteria.add(Expression.eq("jobMode", ProvisionJob.JOB_MODE_DM)); mainCriteria.add(Expression.eq("state", ProvisionJob.JOB_STATE_APPLIED)); if (scheduled) { mainCriteria.add(Expression.le("scheduledTime", new Date())); } mainCriteria.addOrder(Order.asc("scheduledTime")); mainCriteria.addOrder(Order.asc("ID")); Criteria elementCriteria = mainCriteria.createCriteria("provisionElements"); Criteria deviceStatus = elementCriteria.createCriteria("deviceProvReqs"); // DeviceJobStatus are READY, NOTIFIED or Doing Disjunction states = Expression.disjunction(); states.add(Expression.eq("state", ProvisionJobStatus.DEVICE_JOB_STATE_READY)); states.add(Expression.eq("state", ProvisionJobStatus.DEVICE_JOB_STATE_NOTIFIED)); states.add(Expression.eq("state", ProvisionJobStatus.DEVICE_JOB_STATE_DOING)); deviceStatus.add(states); return mainCriteria.list(); } catch (HibernateException ex) { throw new DMException(ex); } }
From source file:com.npower.dm.hibernate.management.ProvisionJobManagementBeanImpl.java
License:Open Source License
public ProvisionJobStatus getProvisionJobStatus(ProvisionJob job, Device device) throws DMException { Session session = null;// w w w. j a va 2s . c om try { session = this.getHibernateSession(); Criteria mainCriteria = session.createCriteria(DeviceProvisionRequestEntity.class); mainCriteria.add(Expression.eq("device", device)); Criteria elementCriteria = mainCriteria.createCriteria("provisionElement"); elementCriteria.add(Expression.eq("provisionRequest", job)); List<DeviceProvisionRequestEntity> states = mainCriteria.list(); if (states != null && states.size() == 1) { return (ProvisionJobStatus) states.get(0); } else { return null; /* if (states == null || states.size() == 0) { // This device is not the target of this job. throw new DMException("error in data constrain, none status boundled with the device."); } else { throw new DMException("error in data constrain, multiple status boundled with the device."); } */ } } catch (Exception ex) { throw new DMException(ex); } }
From source file:com.npower.dm.hibernate.management.ProvisionJobManagementBeanImpl.java
License:Open Source License
public ProfileAssignment getProfileAssignment(ProvisionJob job, Device device) throws DMException { Session session = null;/*from w w w .j av a 2s . c o m*/ try { session = this.getHibernateSession(); Criteria mainCriteria = session.createCriteria(ProfileAssignmentEntity.class); mainCriteria.add(Expression.eq("device", device)); Criteria subCriteria = mainCriteria.createCriteria("jobAssignmentses"); Criteria jobStateCriteria = subCriteria.createCriteria("jobState"); jobStateCriteria.add(Expression.eq("provisionRequest", job)); List<ProfileAssignmentEntity> results = mainCriteria.list(); if (results != null && results.size() == 1) { return (ProfileAssignment) results.get(0); } else { if (results == null || results.size() == 0) { // This device is not the target of this job. return null; } else { throw new DMException( "error in data constrain, multiple ProfileAssignment boundled with the device:" + device.getID() + " and Job: " + job.getID() + "."); } } } catch (Exception ex) { throw new DMException(ex); } }
From source file:com.npower.dm.hibernate.management.SoftwareBeanImpl.java
License:Open Source License
public SoftwarePackage getPackage(Software software, Model model) throws DMException { Session session = this.getHibernateSession(); try {//w w w .ja va 2 s .co m Criteria criteria = session.createCriteria(SoftwarePackageEntity.class); criteria.add(Expression.eq("software", software)); Criteria modelCrit = criteria.createCriteria("packageModels"); String familyExternalID = model.getFamilyExternalID(); // "OR", ModelFamily, Model, ModelClassification Disjunction disjunction = Expression.disjunction(); disjunction.add(Expression.eq("model", model)); if (StringUtils.isNotEmpty(familyExternalID)) { disjunction.add(Expression.eq("modelFamilyExtID", familyExternalID)); } ModelClassificationBean mcBean = this.getManagementBeanFactory().createModelClassificationBean(); List<ModelClassification> modelClasses = mcBean.getModelClassByModel(model); for (ModelClassification modelClass : modelClasses) { disjunction.add(Expression.eq("modelClassification", modelClass)); } modelCrit.add(disjunction); List<SoftwarePackage> list = criteria.list(); if (list.size() == 0) { return null; } return (SoftwarePackage) list.get(0); /* if (list.size() == 1) { return (SoftwarePackage) list.get(0); } else { throw new DMException("Result is not unique, more than one SoftwarePackageEntities have the same model and software: softwareID" + software.getId() + ", modelID: " + model.getID()); } */ } catch (HibernateException e) { throw new DMException(e); } finally { } }
From source file:com.npower.dm.hibernate.management.SoftwareTopListBean4TopList.java
License:Open Source License
private Criteria prepareCriteria(Class<?> clazz, SoftwareCategory category, SoftwareTrackingType trackingEvent, int maxRecords) throws DMException { ManagementBeanFactory factory = this.getManagementBeanFactory(); SearchBean bean = factory.createSearchBean(); Criteria criteria = bean.newCriteriaInstance(clazz); String trackingType = trackingEvent.toString(); criteria.add(Expression.eq("trackingType", trackingType)); criteria.setMaxResults(maxRecords);//from w w w . ja va2 s .com criteria.addOrder(Order.desc("count")); Criteria criteria4Software = criteria.createCriteria("software"); Criteria criteria4Categories = criteria4Software.createCriteria("softwareCategoriesSet"); if (category != null) { Set<SoftwareCategory> targetCategories = this.getTargetCategories(category); criteria4Categories.add(Expression.in("id.category", targetCategories)); } return criteria; }
From source file:com.npower.dm.hibernate.management.UpdateImageManagementBeanImpl.java
License:Open Source License
public List<Update> findUpdates4Upgrade(Model model, String versionId) throws DMException { Image image = this.getImageByVersionID(model, versionId); if (image == null) { return new ArrayList<Update>(0); }// ww w . j ava 2s .c o m Session session = this.getHibernateSession(); long releaseStatus = Image.STATUS_RELEASED; try { ImageUpdateStatus status = getImageUpdateStatus(releaseStatus); Criteria criteria = session.createCriteria(Update.class); criteria.add(Expression.eq("fromImage", image)); criteria.add(Expression.eq("status", status)); Criteria upgradeCriteria = criteria.createCriteria("toImage"); upgradeCriteria.add(Expression.gt("versionId", image.getVersionId())); upgradeCriteria.addOrder(Order.asc("versionId")); return criteria.list(); } catch (HibernateException e) { throw new DMException(e); } finally { } }
From source file:com.npower.dm.hibernate.management.UpdateImageManagementBeanImpl.java
License:Open Source License
public List<Update> findUpdates4Downgrade(Model model, String versionId) throws DMException { Image image = this.getImageByVersionID(model, versionId); if (image == null) { return new ArrayList<Update>(0); }//from w w w . j a v a 2 s .co m Session session = this.getHibernateSession(); long releaseStatus = Image.STATUS_RELEASED; try { ImageUpdateStatus status = getImageUpdateStatus(releaseStatus); Criteria criteria = session.createCriteria(Update.class); criteria.add(Expression.eq("fromImage", image)); criteria.add(Expression.eq("status", status)); Criteria upgradeCriteria = criteria.createCriteria("toImage"); upgradeCriteria.addOrder(Order.desc("versionId")); upgradeCriteria.add(Expression.lt("versionId", image.getVersionId())); return criteria.list(); } catch (HibernateException e) { throw new DMException(e); } finally { } }