List of usage examples for org.hibernate Criteria createCriteria
public Criteria createCriteria(String associationPath, String alias) throws HibernateException;
From source file:de.sub.goobi.forms.StatistikForm.java
License:Open Source License
@SuppressWarnings("unchecked") private int getAnzahlAktuelleSchritte(boolean inOffen, boolean inBearbeitet) { /* aktuellen Benutzer ermitteln */ LoginForm login = (LoginForm) Helper.getManagedBeanValue("#{LoginForm}"); if (login.getMyBenutzer() == null) { return 0; }//from w w w. j av a2 s . c o m try { Session session = Helper.getHibernateSession(); Criteria crit = session.createCriteria(Task.class); /* Liste der IDs */ List<Integer> trefferListe = new ArrayList<Integer>(); /* * die Treffer der Benutzergruppen */ Criteria critGruppen = session.createCriteria(Task.class); if (!inOffen && !inBearbeitet) { critGruppen.add(Restrictions.or(Restrictions.eq("processingStatus", Integer.valueOf(1)), Restrictions.like("processingStatus", Integer.valueOf(2)))); } if (inOffen) { critGruppen.add(Restrictions.eq("processingStatus", Integer.valueOf(1))); } if (inBearbeitet) { critGruppen.add(Restrictions.eq("processingStatus", Integer.valueOf(2))); } /* nur Prozesse, die keine Vorlagen sind */ critGruppen.createCriteria("process", "proz"); critGruppen.add(Restrictions.eq("proz.template", Boolean.FALSE)); /* * nur Schritte, wo Benutzergruppen des aktuellen Benutzers * eingetragen sind */ critGruppen.createCriteria("userGroups", "gruppen").createCriteria("users", "gruppennutzer"); critGruppen.add(Restrictions.eq("gruppennutzer.id", login.getMyBenutzer().getId())); /* die Treffer sammeln */ for (Iterator<Task> iter = critGruppen.list().iterator(); iter.hasNext();) { Task step = iter.next(); trefferListe.add(step.getId()); } /* * Treffer der Benutzer */ Criteria critBenutzer = session.createCriteria(Task.class); if (!inOffen && !inBearbeitet) { critBenutzer.add(Restrictions.or(Restrictions.eq("processingStatus", Integer.valueOf(1)), Restrictions.like("processingStatus", Integer.valueOf(2)))); } if (inOffen) { critBenutzer.add(Restrictions.eq("processingStatus", Integer.valueOf(1))); } if (inBearbeitet) { critBenutzer.add(Restrictions.eq("processingStatus", Integer.valueOf(2))); } /* nur Prozesse, die keine Vorlagen sind */ critBenutzer.createCriteria("process", "proz"); critBenutzer.add(Restrictions.eq("proz.template", Boolean.FALSE)); /* nur Schritte, wo der aktuelle Benutzer eingetragen ist */ critBenutzer.createCriteria("user", "nutzer"); critBenutzer.add(Restrictions.eq("nutzer.id", login.getMyBenutzer().getId())); /* die Treffer sammeln */ for (Iterator<Task> iter = critBenutzer.list().iterator(); iter.hasNext();) { Task step = iter.next(); trefferListe.add(step.getId()); } /* * nun nur die Treffer bernehmen, die in der Liste sind */ crit.add(Restrictions.in("id", trefferListe)); return crit.list().size(); } catch (HibernateException he) { Helper.setFehlerMeldung("fehlerBeimEinlesen", he.getMessage()); return 0; } }
From source file:de.sub.goobi.helper.ProjectHelper.java
License:Open Source License
/** * static to reduce load/* w ww.j a va 2s . c om*/ * * @param project * object * @return a GoobiCollection of the following structure: GoobiCollection 1-n * representing the steps each step has the following properties @ * stepTitle, stepOrder, * stepCount,stepImageCount,totalProcessCount,totalImageCount which * can get extracted by the IGoobiCollection Interface using the * getItem(<name>) method standard workflow of the project * according to the definition that only steps shared by all * processes are returned. The workflow order is returned according * to the average order return by a grouping by step title consider * workflow structure to be a prototype, it would probably make * things easier, to either assemble the underlying construction in * separate classes or to create a new class with these properties */ @SuppressWarnings("unchecked") public static synchronized List<StepInformation> getProjectWorkFlowOverview(Project project) { Long totalNumberOfProc = 0l; Long totalNumberOfImages = 0l; Session session = Helper.getHibernateSession(); Criteria critTotals = session.createCriteria(Process.class, "proc"); critTotals.add(Restrictions.eq("proc.template", Boolean.FALSE)); critTotals.add(Restrictions.eq("proc.project", project)); ProjectionList proList = Projections.projectionList(); proList.add(Projections.count("proc.id")); proList.add(Projections.sum("proc.sortHelperImages")); critTotals.setProjection(proList); List<Object> list = critTotals.list(); for (Object obj : list) { Object[] row = (Object[]) obj; totalNumberOfProc = (Long) row[FieldList.totalProcessCount.fieldLocation]; totalNumberOfImages = (Long) row[FieldList.totalImageCount.fieldLocation]; ; } proList = null; list = null; Criteria critSteps = session.createCriteria(Task.class); critSteps.createCriteria("process", "proc"); critSteps.addOrder(Order.asc("ordering")); critSteps.add(Restrictions.eq("proc.template", Boolean.FALSE)); critSteps.add(Restrictions.eq("proc.project", project)); proList = Projections.projectionList(); proList.add(Projections.groupProperty(("title"))); proList.add(Projections.count("id")); proList.add(Projections.avg("ordering")); critSteps.setProjection(proList); // now we have to discriminate the hits where the max number of hits // doesn't reach numberOfProcs // and extract a workflow, which is the workflow common for all // processes according to its titel // the position will be calculated by the average of 'reihenfolge' of // steps list = critSteps.list(); String title; Double averageStepOrder; Long numberOfSteps; Long numberOfImages; List<StepInformation> workFlow = new ArrayList<>(); for (Object obj : list) { Object[] row = (Object[]) obj; title = (String) (row[FieldList.stepName.fieldLocation]); numberOfSteps = (Long) (row[FieldList.stepCount.fieldLocation]); averageStepOrder = (Double) (row[FieldList.stepOrder.fieldLocation]); // in this step we only take the steps which are present in each of // the workflows if (numberOfSteps.equals(totalNumberOfProc)) { StepInformation newStep = new StepInformation(title, averageStepOrder); newStep.setNumberOfTotalImages(totalNumberOfImages.intValue()); newStep.setNumberOfTotalSteps(totalNumberOfProc.intValue()); workFlow.add(newStep); } } Criteria critStepDone = session.createCriteria(Task.class, "step"); critStepDone.createCriteria("process", "proc"); critStepDone.add(Restrictions.eq("step.processingStatus", TaskStatus.DONE.getValue())); critStepDone.add(Restrictions.eq("proc.template", Boolean.FALSE)); critStepDone.add(Restrictions.eq("proc.project", project)); ProjectionList proCount = Projections.projectionList(); proCount.add(Projections.groupProperty(("step.title"))); proCount.add(Projections.count("proc.id")); proCount.add(Projections.sum("proc.sortHelperImages")); critStepDone.setProjection(proCount); list = critStepDone.list(); for (Object obj : list) { Object[] row = (Object[]) obj; title = (String) (row[FieldList.stepName.fieldLocation]); numberOfSteps = (Long) (row[FieldList.stepCount.fieldLocation]); numberOfImages = (Long) (row[FieldList.imageCount.fieldLocation]); // getting from the workflow collection the collection which // represents step <title> // we only created one for each step holding the counts of processes for (StepInformation currentStep : workFlow) { if (currentStep.getTitle().equals(title)) { currentStep.setNumberOfStepsDone(numberOfSteps.intValue()); currentStep.setNumberOfImagesDone(numberOfImages.intValue()); } } } Comparator<StepInformation> comp = new compareWorkflowSteps(); Collections.sort(workFlow, comp); return workFlow; }
From source file:de.tudarmstadt.ukp.lmf.api.UbyStatistics.java
License:Apache License
/** * Return a {@link Set} of {@link String} instances consisting of <code>lemma+"_"+part-of-speech</code>, * filtered by given {@link Lexicon} name.<br> * The lemma is obtained from the written form of the first {@link FormRepresentation} of the {@link Lemma} * instance.//from w w w . ja v a 2 s . co m * @param lexiconName * name of the lexicon which lemmas should be used * * @return a set of strings containing lemma and part-of-speech of the specified lexicon.<br> * This method returns an empty set if the lexicon with the specified name does no exist. * * @see Lemma#getFormRepresentations() * @see FormRepresentation#getWrittenForm() * @see EPartOfSpeech */ public Set<String> getLemmaPosPerLexicon(String lexiconName) { Criteria criteria = session.createCriteria(Lexicon.class, "l"); criteria = criteria.createCriteria("lexicalEntries", "e"); if (lexiconName != null) { criteria = criteria.add(Restrictions.eq("l.name", lexiconName)); } criteria = criteria.createCriteria("lemma").createCriteria("formRepresentations", "f") .setProjection(Projections.projectionList().add(Property.forName("f.writtenForm")) .add(Property.forName("e.partOfSpeech"))); ScrollableResults res = criteria.scroll(); ArrayList<String> out = new ArrayList<String>(); while (res.next()) { Object[] r = res.get(); if (r[1] != null) { // some resources do not have POS out.add((String) r[0] + "_" + ((EPartOfSpeech) r[1]).toString()); } else { out.add((String) r[0] + "_null"); } } HashSet<String> out2 = new HashSet<String>(out); return out2; }
From source file:de.tudarmstadt.ukp.lmf.api.UbyStatistics.java
License:Apache License
/** * Return a {@link Set} of {@link String} instances consisting of <code>lemma+"_"+part-of-speech</code>, * filtered by given {@link Lexicon} name, part-of-speech prefix and a language identifier.<br> * The lemma is obtained from the written form of the first {@link FormRepresentation} of the {@link Lemma} * instance./* w w w . ja va2s.c om*/ * * @param lexiconName * name of the lexicon which lemmas should be used * * @param prefix the part-of-speech prefix used when filtering {@link LexicalEntry} instances * * @param lang the language identifier used when filtering lexical entries * * @return a set of strings containing lemma and part-of-speech of the specified lexicon.<br> * * This method returns an empty set if the lexicon with the specified name does no exist or * the lexicon does not contain any lexical entries with specified part-of-speech prefix and language * identifier. * * @see Lemma#getFormRepresentations() * @see FormRepresentation#getWrittenForm() * @see EPartOfSpeech * @see ELanguageIdentifier */ public Set<String> getLemmaPosPerLexiconAndPosPrefixAndLanguage(String lexiconName, String prefix, String lang) { Criteria criteria = session.createCriteria(Lexicon.class, "l"); criteria = criteria.createCriteria("lexicalEntries", "e"); if (lexiconName != null) { criteria = criteria.add(Restrictions.eq("l.name", lexiconName)); } if (lang != null) { criteria = criteria.add(Restrictions.eq("l.languageIdentifier", lang)); } if (prefix != null) { criteria = criteria.add(Restrictions.sqlRestriction("partOfSpeech like '" + prefix + "'")); } criteria = criteria.createCriteria("lemma").createCriteria("formRepresentations", "f") .setProjection(Projections.projectionList().add(Property.forName("f.writtenForm")) .add(Property.forName("e.partOfSpeech"))); ScrollableResults res = criteria.scroll(); ArrayList<String> out = new ArrayList<String>(); while (res.next()) { Object[] r = res.get(); if (r[1] != null) { out.add((String) r[0] + "_" + ((EPartOfSpeech) r[1]).toString()); } else { out.add((String) r[0] + "_null"); } } HashSet<String> out2 = new HashSet<String>(out); return out2; }
From source file:es.pode.auditoria.CriteriaSearch.java
/** * Locates a <code>Criteria</code> for a <code>childEntityName</code>. If a * <code>Criteria</code> exists for the <code>childEntityName</code>, it is returned. If * not, one is created and referenced in the <code>childCriteriaMap</code> under the * <code>childEntityName</code>. * * @param childEntityName//from w w w . ja v a 2 s.co m * @param parentCriteria * @return criteria The Criteria for the childEntityName. * @throws org.hibernate.HibernateException */ private org.hibernate.Criteria locateCriteriaLeftJoin(String childEntityName, org.hibernate.Criteria parentCriteria) throws org.hibernate.HibernateException { if (this.childCriteriaMap.containsKey(childEntityName)) { return (org.hibernate.Criteria) this.childCriteriaMap.get(childEntityName); } org.hibernate.Criteria childCriteria = parentCriteria.createCriteria(childEntityName, org.hibernate.sql.JoinFragment.LEFT_OUTER_JOIN); this.childCriteriaMap.put(childEntityName, childCriteria); return childCriteria; }
From source file:es.sm2.openppm.core.dao.EmployeeDAO.java
License:Open Source License
/** * Find Approvals Time Sheets by Functional Manager * /*from w ww . ja va 2s.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.MilestoneDAO.java
License:Open Source License
/** * Find milestones filter by projects and milestone type and dates * //from ww w .j a va 2s. co m * @param projects * @param milestonetype * @param milestonecategory * @param until * @param since * @param milestonePending * @param property * @param order * @param joins * @return */ @SuppressWarnings("unchecked") public List<Milestones> filter(List<Project> projects, Milestonetype milestonetype, Milestonecategory milestonecategory, Date since, Date until, String milestonePending, String property, String order, List<String> joins) { List<Milestones> list = new ArrayList<Milestones>(); if (ValidateUtil.isNotNull(projects)) { Criteria crit = getSession().createCriteria(getPersistentClass()); // Filter dates // if (since != null & until != null) { crit.add(Restrictions.disjunction() .add(Restrictions.conjunction().add(Restrictions.isNotNull(Milestones.ACHIEVED)) .add(Restrictions.between(Milestones.ACHIEVED, since, until))) .add(Restrictions.conjunction().add(Restrictions.isNotNull(Milestones.ESTIMATEDDATE)) .add(Restrictions.between(Milestones.ESTIMATEDDATE, since, until))) .add(Restrictions.conjunction().add(Restrictions.isNotNull(Milestones.PLANNED)) .add(Restrictions.between(Milestones.PLANNED, since, until)))); } else if (since != null) { crit.add(Restrictions.disjunction() .add(Restrictions.conjunction().add(Restrictions.isNotNull(Milestones.ACHIEVED)) .add(Restrictions.ge(Milestones.ACHIEVED, since))) .add(Restrictions.conjunction().add(Restrictions.isNotNull(Milestones.ESTIMATEDDATE)) .add(Restrictions.ge(Milestones.ESTIMATEDDATE, since))) .add(Restrictions.conjunction().add(Restrictions.isNotNull(Milestones.PLANNED)) .add(Restrictions.ge(Milestones.PLANNED, since)))); } else if (until != null) { crit.add(Restrictions.disjunction() .add(Restrictions.conjunction().add(Restrictions.isNotNull(Milestones.ACHIEVED)) .add(Restrictions.le(Milestones.ACHIEVED, until))) .add(Restrictions.conjunction().add(Restrictions.isNotNull(Milestones.ESTIMATEDDATE)) .add(Restrictions.le(Milestones.ESTIMATEDDATE, until))) .add(Restrictions.conjunction().add(Restrictions.isNotNull(Milestones.PLANNED)) .add(Restrictions.le(Milestones.PLANNED, until)))); } // Filter by projects // crit.add(Restrictions.in(Milestones.PROJECT, projects)); // Filter by milestone type // if (milestonetype != null) { crit.add(Restrictions.eq(Milestones.MILESTONETYPE, milestonetype)); } // Filter by milestone category // if (milestonecategory != null) { crit.add(Restrictions.eq(Milestones.MILESTONECATEGORY, milestonecategory)); } // Filter by pendings // if (MilestonePending.YES.name().equals(milestonePending)) { crit.add(Restrictions.isNull(Milestones.ACHIEVED)); } else if (MilestonePending.NO.name().equals(milestonePending)) { crit.add(Restrictions.isNotNull(Milestones.ACHIEVED)); } // Left join milestone type for null relation crit.createCriteria(Milestones.MILESTONETYPE, CriteriaSpecification.LEFT_JOIN); // Joins addJoins(crit, joins); // Orders addOrder(crit, property, order); list = crit.list(); } return list; }
From source file:eu.interedition.text.query.QueryCriterion.java
License:Apache License
public Criteria criteria(Session session) { final Criteria c = session.createCriteria(Annotation.class); c.createAlias("name", "name"); c.createCriteria("targets", "target").createCriteria("text", "text").createAlias("layer", "layer", JoinType.LEFT_OUTER_JOIN);/*from w ww. j av a 2 s .co m*/ return c.add(getRoot().restrict()); }
From source file:fr.mcc.ginco.dao.hibernate.ThesaurusConceptDAO.java
License:CeCILL license
private List<ThesaurusConcept> getConcepts(String conceptId, String thesaurusId, Boolean searchOrphans, int maxResults) { Criteria criteria = getCurrentSession().createCriteria(ThesaurusConcept.class, "tc"); if ((conceptId != null && !conceptId.isEmpty()) && (thesaurusId != null && !thesaurusId.isEmpty())) { selectRoot(criteria, thesaurusId, conceptId); } else if (conceptId == null || conceptId.isEmpty()) { selectRoot(criteria, thesaurusId); } else {/*from w w w. j a v a 2 s . c o m*/ criteria.createCriteria("tc.parentConcepts", "pc").add(Restrictions.eq("pc.identifier", conceptId)); } selectOrphans(criteria, searchOrphans); if (maxResults > 0) criteria.setMaxResults(maxResults); return criteria.list(); }
From source file:fr.mcc.ginco.dao.hibernate.ThesaurusConceptDAO.java
License:CeCILL license
@Override public List<ThesaurusConcept> getAllRootChildren(ThesaurusConcept concept) { Criteria criteria = getCurrentSession().createCriteria(ThesaurusConcept.class, "tc"); criteria.createCriteria("tc.rootConcepts", "rc") .add(Restrictions.eq("rc.identifier", concept.getIdentifier())); return criteria.list(); }