List of usage examples for org.hibernate.criterion Restrictions not
public static Criterion not(Criterion expression)
From source file:de.tuclausthal.submissioninterface.persistence.dao.impl.ParticipationDAO.java
License:Open Source License
@Override public List<Participation> getMarkersAvailableParticipations(Group group) { if (group.getTutors().size() > 0) { Integer[] ids = new Integer[group.getTutors().size()]; int i = 0; for (Participation participation : group.getTutors()) { ids[i++] = participation.getId(); }//from w ww .j a va 2 s . c o m return getSession().createCriteria(Participation.class) .add(Restrictions.eq("lecture", group.getLecture())) .add(Restrictions.or(Restrictions.eq("role", ParticipationRole.TUTOR.toString()), Restrictions.eq("role", ParticipationRole.ADVISOR.toString()))) .add(Restrictions.not(Restrictions.in("id", ids))).createCriteria("user") .addOrder(Order.asc("lastName")).addOrder(Order.asc("firstName")).list(); } else { return getSession().createCriteria(Participation.class) .add(Restrictions.eq("lecture", group.getLecture())) .add(Restrictions.or(Restrictions.eq("role", ParticipationRole.TUTOR.toString()), Restrictions.eq("role", ParticipationRole.ADVISOR.toString()))) .createCriteria("user").addOrder(Order.asc("lastName")).addOrder(Order.asc("firstName")).list(); } }
From source file:edu.emory.library.tast.database.SourceInformationLookup.java
License:Open Source License
private SourceInformationLookup(Session sess) { List response = sess.createCriteria(Source.class, "s") .add(Restrictions.not(Restrictions.isNull("s.sourceId"))).list(); sources = new Source[response.size()]; index = new SourceIndexPosition[response.size()]; int i = 0;/*from ww w.j a v a 2 s. c om*/ for (Iterator sourceIt = response.iterator(); sourceIt.hasNext();) { Source source = (Source) sourceIt.next(); sources[i] = source; index[i] = new SourceIndexPosition(source.getSourceId(), i); i++; } Arrays.sort(index); sourceNames = new String[response.size()]; for (int j = 0; j < index.length; j++) { sourceNames[j] = index[j].getSourceName(); } }
From source file:edu.ucsb.eucalyptus.cloud.ws.BlockStorage.java
License:Open Source License
/** * Checks to see if a new snapshot of size volSize will exceed the quota * @param volSize/*ww w . j av a 2 s . c o m*/ * @return */ private boolean totalSnapshotSizeLimitExceeded(String snapshotId, int volSize) throws EucalyptusCloudException { int totalSnapshotSize = 0; EntityTransaction dbTrans = Entities.get(SnapshotInfo.class); Criteria query = Entities.createCriteria(SnapshotInfo.class); query.setReadOnly(true); //TODO: zhill, fix this logic by adding a size value to the snapshot record, should do the calculation on the DB // this will be very poor for performance as the number of snapshots increases. //Only look for snaps that are not failed and not error query.add(Restrictions .not(Restrictions.and(Restrictions.eq("status", StorageProperties.Status.failed.toString()), Restrictions.eq("status", StorageProperties.Status.error.toString())))); try { List<SnapshotInfo> snapInfos = (List<SnapshotInfo>) query.list(); for (SnapshotInfo sInfo : snapInfos) { try { totalSnapshotSize += blockManager.getSnapshotSize(sInfo.getSnapshotId()); } catch (EucalyptusCloudException e) { LOG.error(e); } } int sizeLimitGB = WalrusInfo.getWalrusInfo().getStorageMaxTotalSnapshotSizeInGb(); LOG.debug("Snapshot " + snapshotId + " checking snapshot total size of " + totalSnapshotSize + " against limit of " + sizeLimitGB); return (totalSnapshotSize + volSize) > sizeLimitGB; } catch (final Throwable e) { LOG.error("Error finding total snapshot used size " + e.getMessage()); throw new EucalyptusCloudException("Failed to check snapshot total size limit", e); } finally { if (dbTrans.isActive()) { dbTrans.rollback(); } } }
From source file:es.emergya.bbdd.dao.IncidenciaHome.java
License:Open Source License
/** * Actualiza los estados de las incidencias que NO se encuentren en el array * y cuyo estado no es ya el pasado como parmetro. * /*from w ww .j av a 2 s.com*/ * @param idsIncidencias * Array de ids de incidencias * @param estado * Estado a establecer */ @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false, rollbackFor = Throwable.class) public void updateEstadosIncidencias(Long[] idsIncidencias, String estado) { if (idsIncidencias != null && idsIncidencias.length > 0) { EstadoIncidencia estadoObj = getEstadoIncidenciaByIdentificador(estado); if (estado != null) { Criteria crit = getSession().createCriteria(Incidencia.class) .add(Restrictions.not(Restrictions.in("id", idsIncidencias))) .add(Restrictions.ne("estado", estadoObj)); List<Incidencia> resultado = crit.list(); for (Incidencia inc : resultado) { if (log.isTraceEnabled()) { log.trace("Actualizamos el estado de la incidencia " + inc.getId() + " a " + estado); } inc.setEstado(estadoObj); getSession().update(inc); } } else { log.error("El estado " + estado + " no se encuentra en la base de datos"); } } }
From source file:es.emergya.bbdd.dao.PatrullaHome.java
License:Open Source License
/** * Actualiza los recursos de las patrullas que NO se encuentren en el array * // w ww .ja va 2s . c o m * @param idsPatrullas * Array de ids de patrullas * @param estado * Estado a establecer */ @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false, rollbackFor = Throwable.class) public void updateEstadosRecursos(Long[] idsPatrullas, String estado) { if (idsPatrullas != null && idsPatrullas.length > 0) { Criteria crit = getSession().createCriteria(Patrulla.class) .add(Restrictions.not(Restrictions.in("id", idsPatrullas))); List<Patrulla> resultado = crit.list(); EstadoRecurso estadoObj = getEstadoRecursoByIdentificador(estado); if (estado != null) { for (Patrulla pat : resultado) { log.debug("Actualizamos los recursos de la patrulla " + pat.getId()); List<Recurso> recs = getRecursosByPatrulla(pat); log.debug("Recursos:" + recs.size()); if (recs != null && recs.size() > 0) { for (Recurso rec : recs) { log.debug("Actualizamos el recurso " + rec.getId() + " a " + estado); rec.setEstadoEurocop(estadoObj); getSession().update(rec); } } } } else log.error("El estado " + estado + " no se encuentra en la base de datos"); } }
From source file:es.sm2.openppm.core.dao.EmployeeDAO.java
License:Open Source License
/** * Find Approvals Time Sheets by Functional Manager * /*from ww w . java 2 s. c o m*/ * @param user * @param initDate * @param endDate * @param status * @param statusResource * @param includeClosed * @param onlyOperations * @param employees - not equals * @return */ @SuppressWarnings("unchecked") public List<Employee> findApprovals(Employee user, Date initDate, Date endDate, String status, String statusResource, boolean includeClosed, List<Employee> employees, boolean onlyOperations) { Resourceprofiles profile = user.getResourceprofiles(); Criteria crit = getSession().createCriteria(getPersistentClass(), "e") .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).setFetchMode(Employee.CONTACT, FetchMode.JOIN); if (ValidateUtil.isNotNull(employees)) { List<Integer> ids = new ArrayList<Integer>(); for (Employee item : employees) { ids.add(item.getIdEmployee()); } crit.add(Restrictions.not(Restrictions.in("e." + Employee.IDEMPLOYEE, ids))); } crit.createCriteria(Employee.TIMESHEETS, "ts").add(Restrictions.eq(Timesheet.INITDATE, initDate)) .add(Restrictions.eq(Timesheet.ENDDATE, endDate)).add(Restrictions.eq(Timesheet.STATUS, status)) .createAlias(Timesheet.PROJECTACTIVITY, "pa", Criteria.LEFT_JOIN) .createAlias("pa." + Projectactivity.PROJECT, "p", Criteria.LEFT_JOIN); if (ValidateUtil.isNotNull(statusResource)) { crit.createCriteria("pa." + Projectactivity.TEAMMEMBERS) .add(Restrictions.eq(Teammember.STATUS, statusResource)).createCriteria(Teammember.EMPLOYEE) .add(Restrictions.eqProperty(Employee.IDEMPLOYEE, "e." + Employee.IDEMPLOYEE)); } else if (onlyOperations) { crit.add(Restrictions.isNotNull("ts." + Timesheet.OPERATION)); } // Exluce projects closed if (!includeClosed) { crit.add(Restrictions.and(Restrictions.ne("p." + Project.STATUS, Constants.STATUS_CLOSED), Restrictions.ne("p." + Project.STATUS, Constants.STATUS_ARCHIVED))); } // Filter by User. Settings by company for last approval. if (profile.getIdProfile() == Constants.ROLE_FM) { crit.add(Restrictions.or(Restrictions.eq("p." + Project.EMPLOYEEBYFUNCTIONALMANAGER, user), Restrictions.and(Restrictions.isNull("ts." + Timesheet.PROJECTACTIVITY), Restrictions.eq("e." + Employee.PERFORMINGORG, user.getPerformingorg())))); } else if (profile.getIdProfile() == Constants.ROLE_PMO) { crit.add(Restrictions.or(Restrictions.eq("p." + Project.PERFORMINGORG, user.getPerformingorg()), Restrictions.and(Restrictions.isNull("ts." + Timesheet.PROJECTACTIVITY), Restrictions.eq("e." + Employee.PERFORMINGORG, user.getPerformingorg())))); } return crit.list(); }
From source file:es.sm2.openppm.core.dao.EmployeeDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public List<Employee> findInputedInOperations(List<Employee> employees, Date since, Date until, Integer idResourcePool) { List<Employee> returnEmployees = null; if (ValidateUtil.isNotNull(employees)) { Criteria crit = getSession().createCriteria(getPersistentClass()) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); List<Integer> ids = new ArrayList<Integer>(); for (Employee item : employees) { ids.add(item.getIdEmployee()); }/*from ww w. java 2 s.co m*/ crit.add(Restrictions.not(Restrictions.in(Employee.IDEMPLOYEE, ids))); if (idResourcePool != null) { crit.add(Restrictions.eq(Employee.RESOURCEPOOL, new Resourcepool(idResourcePool))); } Criteria sheets = crit.createCriteria(Employee.TIMESHEETS) .add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP3)) .add(Restrictions.isNotNull(Timesheet.OPERATION)); if (since != null && until != null) { sheets.add(Restrictions.disjunction().add(Restrictions.between(Timesheet.INITDATE, since, until)) .add(Restrictions.between(Timesheet.ENDDATE, since, until)) .add(Restrictions.and(Restrictions.le(Timesheet.INITDATE, since), Restrictions.ge(Timesheet.ENDDATE, until)))); } crit.createCriteria(Employee.CONTACT).addOrder(Order.asc(Contact.FULLNAME)); returnEmployees = crit.list(); } return returnEmployees; }
From source file:es.sm2.openppm.core.dao.ProblemcheckDAO.java
License:Open Source License
/** * Find the remaining and active checks// w w w . j a v a2s . com * * @param idsExclude * @param company * @return */ @SuppressWarnings("unchecked") public List<Problemcheck> findbyRemainAndActive(Integer[] idsExclude, Company company) { Criteria crit = getSession().createCriteria(getPersistentClass()) .add(Restrictions.eq(Problemcheck.COMPANY, company)) .add(Restrictions.eq(Problemcheck.SHOWCHECK, true)); // Exclude if (ValidateUtil.isNotNull(idsExclude)) { crit.add(Restrictions.not(Restrictions.in(Problemcheck.IDPROBLEMCHECK, idsExclude))); } // Order crit.addOrder(Order.asc(Problemcheck.NAME)); return crit.list(); }
From source file:es.sm2.openppm.core.dao.ProjectActivityDAO.java
License:Open Source License
/** * List not assigned activities to seller * //w ww .j a v a 2 s .c o m * @param seller * @param project * @param order * @return */ @SuppressWarnings("unchecked") public List<Object[]> consNoAssignedActivities(Seller seller, Project project, Order... order) { Criteria usedCrit = getSession().createCriteria(getPersistentClass()) .setProjection(Projections.property(Projectactivity.IDACTIVITY)) .add(Restrictions.eq(Projectactivity.PROJECT, project)); usedCrit.createCriteria(Projectactivity.ACTIVITYSELLERS) .add(Restrictions.eq(Activityseller.SELLER, seller)); List<Projectactivity> lista = usedCrit.list(); Criteria crit = getSession().createCriteria(getPersistentClass()) .setProjection(Projections.projectionList().add(Projections.property(Projectactivity.IDACTIVITY)) .add(Projections.property(Projectactivity.ACTIVITYNAME))) .add(Restrictions.eq(Projectactivity.PROJECT, project)); crit.createCriteria(Projectactivity.WBSNODE).add(Restrictions.eq(Wbsnode.ISCONTROLACCOUNT, true)); if (!lista.isEmpty()) { crit.add(Restrictions.not(Restrictions.in(Projectactivity.IDACTIVITY, lista))); } for (Order o : order) { crit.addOrder(o); } return crit.list(); }
From source file:es.sm2.openppm.core.dao.RiskRegisterDAO.java
License:Open Source License
/** * Check for closed risks/*from w w w . ja va 2 s . c om*/ * * @param project * @return */ public boolean risksNotClosed(Project project) { Criteria critRisks = getSession().createCriteria(getPersistentClass()).setProjection(Projections.rowCount()) .add(Restrictions.not(Restrictions.eq(Riskregister.STATUS, Constants.CHAR_CLOSED))) .add(Restrictions.eq(Riskregister.PROJECT, project)); Integer count = (Integer) critRisks.uniqueResult(); return (count != null && count > 0); }