List of usage examples for org.hibernate.criterion Restrictions or
public static LogicalExpression or(Criterion lhs, Criterion rhs)
From source file:es.jpons.persistence.query.CriteriaAllenRelations.java
License:Open Source License
public static Criteria starts(Criteria initializedCriteria, PossibilisticVTP pvp) { initializedCriteria = initializedCriteria.add(Restrictions.or( Restrictions.sqlRestriction("({alias}.startMP + {alias}.startRight ) <= ?", pvp.getStartMP() - pvp.getStartLeft(), LongType.INSTANCE), Restrictions.sqlRestriction("({alias}.startMP - {alias}.startLeft ) >= ?", pvp.getStartMP() + pvp.getStartRight(), LongType.INSTANCE))); return initializedCriteria; }
From source file:es.jpons.persistence.query.CriteriaAllenRelations.java
License:Open Source License
public static Criteria ends(Criteria initializedCriteria, PossibilisticVTP pvp) { initializedCriteria = initializedCriteria.add(Restrictions.or( Restrictions.sqlRestriction("({alias}.endMP + {alias}.endRight ) <= ?", pvp.getEndMP() - pvp.getEndLeft(), LongType.INSTANCE), Restrictions.sqlRestriction("({alias}.endMP - {alias}.endLeft ) >= ?", pvp.getEndMP() + pvp.getEndRight(), LongType.INSTANCE))); return initializedCriteria; }
From source file:es.jpons.persistence.TemporalPersistenceManager.java
License:Open Source License
/** * Function that stablishes the constrains for the temporal insertion. * * @param c An initialized criteria object. * @param validTime The valid time to intert * @return A criteria to query the database. *//* w w w . j a v a 2 s .c om*/ protected Criteria criteriaInsert(Criteria c, PossibilisticVTP validTime, TemporalPK key) { if (c == null) { return null; } c = c.add(Restrictions.and(Restrictions.gt("pvp.startMP", validTime.getStartMP()), Restrictions.or( Restrictions.and(Restrictions.lt("pvp.startMP", validTime.getEndMP()), Restrictions.gt("pvp.endMP", validTime.getEndMP())), Restrictions.lt("pvp.endMP", validTime.getEndMP())), Restrictions.eq("tid.id", key.getId()))); return c; }
From source file:es.sm2.openppm.core.dao.ContactDAO.java
License:Open Source License
/** * Search Contacts by filter/*from ww w. j a va2 s. c om*/ * @param resourcepools * @param fullName * @param fileAs * @param performingorg * @param company * @param skills *@param jobcategories @return */ @SuppressWarnings("unchecked") public List<Contact> searchByFilter(String fullName, String fileAs, Performingorg performingorg, Company company, List<Resourcepool> resourcepools, List<Skill> skills, List<Jobcategory> jobcategories) { Contact example = new Contact(); example.setFileAs(fileAs); example.setFullName(fullName); Criteria crit = getSession().createCriteria(getPersistentClass()) .setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY) .add(Example.create(example).ignoreCase().enableLike(MatchMode.ANYWHERE)) .add(Restrictions.or(Restrictions.isNull(Contact.DISABLE), Restrictions.ne(Contact.DISABLE, true))); // Company // crit.createCriteria(Contact.COMPANY).add(Restrictions.idEq(company.getIdCompany())) .add(Restrictions.or(Restrictions.isNull(Company.DISABLE), Restrictions.ne(Company.DISABLE, true))); // Employee Criteria critEmployee = crit.createCriteria(Contact.EMPLOYEES, CriteriaSpecification.LEFT_JOIN); if (performingorg != null && performingorg.getIdPerfOrg() != null && performingorg.getIdPerfOrg() != -1) { critEmployee.createCriteria(Employee.PERFORMINGORG) .add(Restrictions.idEq(performingorg.getIdPerfOrg())); } if (ValidateUtil.isNotNull(resourcepools)) { critEmployee.add(Restrictions.in(Employee.RESOURCEPOOL, resourcepools)); } if (ValidateUtil.isNotNull(skills)) { critEmployee.createCriteria(Employee.SKILLSEMPLOYEES) .add(Restrictions.in(Skillsemployee.SKILL, skills)); } if (ValidateUtil.isNotNull(jobcategories)) { critEmployee.createCriteria(Employee.JOBCATEMPLOYEES) .add(Restrictions.in(Jobcatemployee.JOBCATEGORY, jobcategories)); } return crit.list(); }
From source file:es.sm2.openppm.core.dao.ContactDAO.java
License:Open Source License
/** * Find owners LLAA/* w w w .jav a2 s . c o m*/ * * @param company * @return */ public List<Contact> findUsedInLLAA(Company company) { Criteria crit = getSession().createCriteria(getPersistentClass()) .setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY) .add(Restrictions.eq(Contact.COMPANY, company)) .add(Restrictions.or(Restrictions.isNull(Contact.DISABLE), Restrictions.ne(Contact.DISABLE, true))) .addOrder(Order.asc(Contact.FULLNAME)); crit.createCriteria(Contact.LEARNEDLESSONS).add(Restrictions.eq(LearnedLesson.COMPANY, company)); return crit.list(); }
From source file:es.sm2.openppm.core.dao.EmployeeDAO.java
License:Open Source License
/** * Search Employee By filter/*from w w w . j a v a2s.com*/ * @param name * @param jobTitle * @param idProfile * @param idPerfOrg * @return */ @SuppressWarnings("unchecked") public List<Employee> searchByFilter(String name, String jobTitle, Integer idProfile, Integer idPerfOrg, Company company) { Criteria crit = getSession().createCriteria(getPersistentClass()).add( Restrictions.or(Restrictions.isNull(Employee.DISABLE), Restrictions.ne(Employee.DISABLE, true))); crit.createCriteria(Employee.CONTACT).add(Restrictions.ilike(Contact.FULLNAME, "%" + name + "%")) .add(Restrictions.ilike(Contact.JOBTITLE, "%" + jobTitle + "%")) .add(Restrictions.eq(Contact.COMPANY, company)) .add(Restrictions.or(Restrictions.isNull(Contact.DISABLE), Restrictions.ne(Contact.DISABLE, true))) .createCriteria(Contact.COMPANY) .add(Restrictions.or(Restrictions.isNull(Company.DISABLE), Restrictions.ne(Company.DISABLE, true))); if (idProfile != -1) { crit.add(Restrictions.eq(Employee.RESOURCEPROFILES, new Resourceprofiles(idProfile))); } if (idPerfOrg != -1) { crit.add(Restrictions.eq(Employee.PERFORMINGORG, new Performingorg(idPerfOrg))); } crit.setFetchMode(Employee.CONTACT, FetchMode.JOIN); crit.setFetchMode(Employee.CONTACT + "." + Contact.COMPANY, FetchMode.JOIN); crit.setFetchMode(Employee.PERFORMINGORG, FetchMode.JOIN); return crit.list(); }
From source file:es.sm2.openppm.core.dao.EmployeeDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public List<Employee> consEmployeesByUser(Contact contact) { Criteria crit = getSession().createCriteria(getPersistentClass()).add( Restrictions.or(Restrictions.isNull(Employee.DISABLE), Restrictions.ne(Employee.DISABLE, true))); crit.createCriteria(Employee.RESOURCEPROFILES).addOrder(Order.asc(Resourceprofiles.PROFILENAME)); crit.setFetchMode(Employee.RESOURCEPROFILES, FetchMode.JOIN).setFetchMode(Employee.PERFORMINGORG, FetchMode.JOIN);//w ww . j ava 2 s . c o m crit.createCriteria(Employee.CONTACT).add(Restrictions.idEq(contact.getIdContact())) .add(Restrictions.or(Restrictions.isNull(Contact.DISABLE), Restrictions.ne(Contact.DISABLE, true))) .createCriteria(Contact.COMPANY) .add(Restrictions.or(Restrictions.isNull(Company.DISABLE), Restrictions.ne(Company.DISABLE, true))); return crit.list(); }
From source file:es.sm2.openppm.core.dao.EmployeeDAO.java
License:Open Source License
/** * Find Approvals Time Sheets by Functional Manager * //from w w w .j av a 2s. c om * @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
/** * Find Approvals Expenses by Functional Manager * @param user/*from www . j a v a 2s. c o m*/ * @param since * @param until * @return */ @SuppressWarnings("unchecked") public List<Employee> findApprovalsExpense(Employee user, Date since, Date until) { Criteria crit = getSession().createCriteria(getPersistentClass()) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).setFetchMode(Employee.CONTACT, FetchMode.JOIN); crit.createCriteria(Employee.EXPENSESHEETS) .add(Restrictions.between(Expensesheet.EXPENSEDATE, since, until)) .add(Restrictions.or(Restrictions.eq(Expensesheet.STATUS, Constants.TIMESTATUS_APP2), Restrictions.eq(Expensesheet.STATUS, Constants.TIMESTATUS_APP3))); crit.add(Restrictions.eq(Employee.PERFORMINGORG, user.getPerformingorg())); return crit.list(); }
From source file:es.sm2.openppm.core.dao.EmployeeDAO.java
License:Open Source License
/** * Find Employees where inputed hours is approval * /*ww w. j av a 2 s . c o m*/ * @param project * @param since * @param until * @return */ @SuppressWarnings("unchecked") public List<Employee> findInputedInProject(Project project, Date since, Date until) { Criteria crit = getSession().createCriteria(getPersistentClass()) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); Criteria members = crit.createCriteria(Employee.TEAMMEMBERS) .add(Restrictions.or(Restrictions.eq(Teammember.STATUS, Constants.RESOURCE_ASSIGNED), Restrictions.eq(Teammember.STATUS, Constants.RESOURCE_RELEASED))); if (since != null && until != null) { members.add(Restrictions.disjunction().add(Restrictions.between(Teammember.DATEIN, since, until)) .add(Restrictions.between(Teammember.DATEOUT, since, until)) .add(Restrictions.and(Restrictions.le(Teammember.DATEIN, since), Restrictions.ge(Teammember.DATEOUT, until)))); } members.createCriteria(Teammember.PROJECTACTIVITY).add(Restrictions.eq(Projectactivity.PROJECT, project)); Criteria sheets = crit.createCriteria(Employee.TIMESHEETS) .add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP3)); 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)))); } sheets.createCriteria(Timesheet.PROJECTACTIVITY).add(Restrictions.eq(Projectactivity.PROJECT, project)); crit.createCriteria(Employee.CONTACT).addOrder(Order.asc(Contact.FULLNAME)); crit.setFetchMode(Employee.CALENDARBASE, FetchMode.JOIN); return crit.list(); }