List of usage examples for org.hibernate.criterion Restrictions sqlRestriction
public static Criterion sqlRestriction(String sql)
From source file:de.escidoc.core.common.business.filter.CqlFilter.java
License:Open Source License
/** * Return the given criterion if it is not NULL. Otherwise return "FALSE". * //from ww w . ja va 2 s .co m * @param criterion * Hibernate query or NULL * @return the given Hibernate query or "FALSE" */ private static Criterion getOrRestriction(final Criterion criterion) { return criterion != null ? criterion : Restrictions.sqlRestriction("1 = 0"); }
From source file:de.ingrid.portal.interfaces.impl.DBAnniversaryInterfaceImpl.java
License:EUPL
/** * @see de.ingrid.portal.interfaces.SimilarTermsInterface#getAnniversary(java.sql.Date) *///from www . j a v a 2s . c o m public IngridHitDetail[] getAnniversaries(Date d, String lang) { Session session = HibernateUtil.currentSession(); Transaction tx = null; try { Calendar queryDateFrom = Calendar.getInstance(); queryDateFrom.set(Calendar.HOUR_OF_DAY, 0); queryDateFrom.set(Calendar.MINUTE, 0); queryDateFrom.set(Calendar.SECOND, 0); queryDateFrom.set(Calendar.MILLISECOND, 0); Calendar queryDateTo = Calendar.getInstance(); queryDateTo.set(Calendar.HOUR_OF_DAY, 23); queryDateTo.set(Calendar.MINUTE, 59); queryDateTo.set(Calendar.SECOND, 59); queryDateTo.set(Calendar.MILLISECOND, 0); Calendar fromCal = Calendar.getInstance(); Calendar toCal = Calendar.getInstance(); fromCal.setTime(d); tx = session.beginTransaction(); List anniversaryList = session.createCriteria(IngridAnniversary.class) .add(Restrictions.eq("dateFromDay", new Integer(fromCal.get(Calendar.DAY_OF_MONTH)))) .add(Restrictions.eq("dateFromMonth", new Integer(fromCal.get(Calendar.MONTH) + 1))) .add(Restrictions.eq("language", lang)).list(); tx.commit(); if (anniversaryList.isEmpty()) { // fall back: get any event of this month fromCal.setTime(d); toCal.setTime(d); tx = session.beginTransaction(); anniversaryList = session.createCriteria(IngridAnniversary.class) .add(Restrictions.between("dateFromMonth", new Integer(fromCal.get(Calendar.MONTH) + 1), new Integer(toCal.get(Calendar.MONTH) + 1))) .add(Restrictions.sqlRestriction("length({alias}.date_from) > 4")) .add(Restrictions.eq("language", lang)).list(); tx.commit(); if (anniversaryList.isEmpty()) { // fall back: get any event that has been fetched for today fromCal.setTime(d); tx = session.beginTransaction(); anniversaryList = session.createCriteria(IngridAnniversary.class) .add(Restrictions.eq("language", lang)).list(); tx.commit(); } } IngridHitDetail[] rslt = new IngridHitDetail[anniversaryList.size()]; for (int i = 0; i < rslt.length; i++) { IngridAnniversary anni = (IngridAnniversary) anniversaryList.get(i); rslt[i] = new DetailedTopic(); rslt[i].put("topicId", anni.getTopicId()); rslt[i].put("topicName", anni.getTopicName()); rslt[i].put("from", anni.getDateFrom()); rslt[i].put("until", anni.getDateTo()); rslt[i].put("until", anni.getDateTo()); session.evict(anni); } return rslt; } catch (Exception e) { if (tx != null && tx.isActive()) { tx.rollback(); } if (log.isErrorEnabled()) { log.error("Exception while querying sns for anniversary.", e); } return new DetailedTopic[0]; } finally { HibernateUtil.closeSession(); } }
From source file:de.tuclausthal.submissioninterface.persistence.dao.impl.GroupDAO.java
License:Open Source License
@Override public List<Group> getJoinAbleGroups(Lecture lecture, Group participationGroup) { if (participationGroup == null) { return getSession().createCriteria(Group.class).add(Restrictions.eq("lecture", lecture)) .add(Restrictions.eq("allowStudentsToSignup", true)) .add(Restrictions.sqlRestriction( "(select count(*) from participations where groupid={alias}.gid) < this_.maxStudents")) .list();// w ww. ja va 2s . c om } else { return getSession().createCriteria(Group.class).add(Restrictions.eq("lecture", lecture)) .add(Restrictions.eq("allowStudentsToSignup", true)) .add(Restrictions.sqlRestriction( "(select count(*) from participations where groupid={alias}.gid) < this_.maxStudents")) .add(Restrictions.not(Restrictions.eq("gid", participationGroup.getGid()))).list(); } }
From source file:de.tuclausthal.submissioninterface.persistence.dao.impl.LectureDAO.java
License:Open Source License
@Override public List<Lecture> getCurrentLecturesWithoutUser(User user) { Session session = getSession();/*w w w . j a va2 s . co m*/ // Criteria a = session.createCriteria(Lecture.class).createCriteria("participants").add(Restrictions.isNull("lecture")).createCriteria("user", Criteria.FULL_JOIN); return session.createCriteria(Lecture.class).add(Restrictions.ge("semester", Util.getCurrentSemester())) .addOrder(Order.asc("name")) .add(Restrictions.sqlRestriction( "{alias}.id not in (select lectureid from participations part where part.uid=" + user.getUid() + ")")) .list(); }
From source file:de.tuclausthal.submissioninterface.persistence.dao.impl.ParticipationDAO.java
License:Open Source License
@Override public List<Participation> getParticipationsWithNoSubmissionToTaskOrdered(Task task) { return getSession().createCriteria(Participation.class) .add(Restrictions.eq("lecture", task.getTaskGroup().getLecture())) .add(Restrictions.sqlRestriction( "{alias}.id not in (SELECT submitters_id FROM submissions, submissions_participations where submissions.submissionid=submissions_participations.submissions_submissionid and taskid=" + task.getTaskid() + ")")) .createCriteria("user").addOrder(Order.asc("lastName")).addOrder(Order.asc("firstName")).list(); }
From source file:de.tudarmstadt.ukp.lmf.api.Uby.java
License:Apache License
/** * This method finds all {@link SenseAxis} instances which id contains the specified * {@link String} in the database accessed by this {@link Uby} instance. * * @param senseAxisId//from www . j av a 2 s .co m * string contained in the identifiers of the sense axes to be returned * * @return the {@link List} of all sense axes which id contains the specified string.<br> * This method returns an empty list if no sense axis contains the specified string in * its id or the specified string is null. * * @see #getSenseAxes() * @see #getSenseAxesBySense(Sense) * @see #getSenseAxesByIdPattern(String) */ public List<SenseAxis> getSenseAxesByIdPattern(String senseAxisId) { Criteria criteria = session.createCriteria(SenseAxis.class); criteria = criteria.add(Restrictions.sqlRestriction("senseAxisId like '%" + senseAxisId + "%'")); @SuppressWarnings("unchecked") List<SenseAxis> result = criteria.list(); if (result == null) { result = new ArrayList<SenseAxis>(0); } return result; }
From source file:de.tudarmstadt.ukp.lmf.api.Uby.java
License:Apache License
/** * Returns a {@link List} of all {@link Sense} instances which unique identifier contains the * consumed {@link String}./*from w ww . j av a 2 s .c om*/ * * @param idPattern * the pattern which identifiers of the returned senses must contain * @return the list of all senses which unique identifier contains the idPattern * <p> * If none of the senses contained in the UBY-Database accessed by this {@link Uby} * instance contains the consumed pattern this method returns an empty list. */ public List<Sense> getSensesbyIdPattern(String idPattern) { Criteria criteria = session.createCriteria(Sense.class); criteria = criteria.add(Restrictions.sqlRestriction("senseId like '%" + idPattern + "%'")); @SuppressWarnings("unchecked") List<Sense> result = criteria.list(); return result; }
From source file:de.tudarmstadt.ukp.lmf.api.Uby.java
License:Apache License
/** * @deprecated use {@link #wordNetSenses(String, String)} or * {@link #wordNetSense(String, String)} instead *//*from www. ja v a 2 s . c o m*/ @SuppressWarnings("unchecked") @Deprecated public List<Sense> getWNSensebyExtRef(String offset, String POS) throws ClassNotFoundException, SQLException { String refId = "[POS: noun] "; if (POS.equals("adjective")) { refId = refId.replaceAll("noun", "adjective"); } else if (POS.equals("adverb")) { refId = refId.replaceAll("noun", "adverb"); } else if (POS.equals("verb")) { refId = refId.replaceAll("noun", "verb"); } refId = refId + offset; /* * This direct query avoids the joining huge table done by using normal hibernate, while we just need the ID */ String sqlQueryString = "SELECT synsetId FROM MonolingualExternalRef WHERE externalReference = '" + refId.trim() + "'"; SQLQuery query = session.createSQLQuery(sqlQueryString); @SuppressWarnings("rawtypes") Iterator iter = query.list().iterator(); String ss_id = ""; while (iter.hasNext()) { ss_id = (String) iter.next(); } Criteria criteria = session.createCriteria(Sense.class); criteria = criteria.add(Restrictions.sqlRestriction("synsetId='" + ss_id.trim() + "'")); return criteria.list(); }
From source file:de.tudarmstadt.ukp.lmf.api.Uby.java
License:Apache License
/** * @param POS/*from www . jav a 2 s. com*/ * : POS value=comment<br> * a = adj;<br> * n = noun;<br> * r = adv<br> * v = verb<br> * @param SynsetOffset * : offset value of Synset; * @return list of senses belong to the given synset * @Deprecated use {@link #wordNetSenses(String, String)} or * {@link #wordNetSense(String, String)} instead */ @Deprecated public List<Sense> getSensesByWNSynsetId(String POS, String SynsetOffset) throws ClassNotFoundException, SQLException { String refId = "[POS: noun] "; if (POS.equals("a")) { refId = refId.replaceAll("noun", "adjective"); } else if (POS.equals("r")) { refId = refId.replaceAll("noun", "adverb"); } else if (POS.equals("v")) { refId = refId.replaceAll("noun", "verb"); } refId = refId + SynsetOffset; Criteria criteria = session.createCriteria(Sense.class); criteria = criteria.createCriteria("monolingualExternalRefs") .add(Restrictions.sqlRestriction("externalReference='" + refId.trim() + "'")); @SuppressWarnings("unchecked") List<Sense> result = criteria.list(); return result; }
From source file:de.tudarmstadt.ukp.lmf.api.Uby.java
License:Apache License
/** * Consumes a synset identifier (in WordNet terminology) and returns a {@link List} of * {@link Sense} instances which are derived from the WordNets synset, specified by the consumed * identifier./* www . j av a2 s . com*/ * * @param wnSynsetId * string representation of the WordNets synset identifier i.e. "1740-n" * * @return a list of senses derived from the WordNets synset, specified by the consumed * identifier * <p> * This method returns an empty list if the database accessed by this {@link Uby} * instance does not contain senses derived from the specified WordNet synset. * * @deprecated use {@link #wordNetSense(String, String)} and * {@link #wordNetSense(String, String)} instead */ @Deprecated public List<Sense> getSensesByWNSynsetId(String wnSynsetId) { String[] temp = wnSynsetId.split("-"); String refId = "[POS: noun] "; if (temp[1].equals("a")) { refId = refId.replaceAll("noun", "adjective"); } else if (temp[1].equals("r")) { refId = refId.replaceAll("noun", "adverb"); } else if (temp[1].equals("v")) { refId = refId.replaceAll("noun", "verb"); } refId = refId + temp[0]; Criteria criteria = session.createCriteria(Sense.class); criteria = criteria.createCriteria("synset").createCriteria("monolingualExternalRefs") .add(Restrictions.sqlRestriction("externalReference='" + refId.trim() + "'")); @SuppressWarnings("unchecked") List<Sense> result = criteria.list(); return result; }