List of usage examples for org.hibernate.criterion Restrictions and
public static LogicalExpression and(Criterion lhs, Criterion rhs)
From source file:de.tuclausthal.submissioninterface.persistence.dao.impl.SimilarityDAO.java
License:Open Source License
@Override public void addSimilarityResult(SimilarityTest similarityTest, Submission submissionOne, Submission submissionTwo, int percentage) { // TODO: check in plaggie that only submissiondirectories are considered if (submissionOne != null && submissionTwo != null) { Session session = getSession();/*from w w w . j ava2 s. c om*/ Transaction tx = session.beginTransaction(); for (Similarity similarity : (List<Similarity>) session.createCriteria(Similarity.class) .add(Restrictions.eq("similarityTest", similarityTest)) .add(Restrictions.or( Restrictions.and(Restrictions.eq("submissionOne", submissionOne), Restrictions.eq("submissionTwo", submissionTwo)), Restrictions.and(Restrictions.eq("submissionOne", submissionTwo), Restrictions.eq("submissionTwo", submissionOne)))) .list()) { session.delete(similarity); } Similarity simularity; simularity = new Similarity(similarityTest, submissionOne, submissionTwo, percentage); session.save(simularity); simularity = new Similarity(similarityTest, submissionTwo, submissionOne, percentage); session.save(simularity); tx.commit(); } }
From source file:de.tudarmstadt.ukp.lmf.api.Uby.java
License:Apache License
/** * Returns the {@link Sense} instance contained in the database accessed by this {@link Uby} * instance. The returned senses are filtered by the given name of the external system and * external reference./*from w w w .j a v a 2 s.c o m*/ * * @param externalSys * the {@link String} representing the name of external system such as: * FrameNet_1.5_eng_lexicalUnit VerbNet_3.1_eng_sense * OmegaWiki_<version>_<language>_synTrans WordNet_3.0_eng_senseKey * Wiktionary_<version>_<language>_sense Wikipedia_<version>_<language>_articleTitle * GermaNet_7.0_deu_lexicalUnit * @param externalRef * the reference string from external system, such as: * <ul> * <li>WordNet: "[POS: noun] house%1:15:00::" - POS and sense key Returns a list of * one sense</li> * <li>VerbNet: "retire_withdraw-82-3" Several UBY senses can have the same original * sense ID</li> * <li>FrameNet: "2676" - lexical unit ID</li> * <li>Wiktionary: "16:0:1" - sense key</li> * <li>Wikipedia: "House" - article title</li> * <li>OW: "303002" - OW SynTrans Id</li> * </ul> * @return a {@link List} of all senses filtered by the given arguments or an empty list if if * one of the given arguments is null or the accessed database does not contain any * senses matching both constraints */ public List<Sense> getSensesByOriginalReference(String externalSys, String externalRef) { Criteria criteria = session.createCriteria(Sense.class); criteria = criteria.createCriteria("monolingualExternalRefs").add(Restrictions.and( Restrictions.eq("externalSystem", externalSys), Restrictions.eq("externalReference", externalRef))); @SuppressWarnings("unchecked") List<Sense> result = criteria.list(); if (result == null) { result = new ArrayList<Sense>(0); } return result; }
From source file:de.tudarmstadt.ukp.lmf.api.Uby.java
License:Apache License
/** * Returns the {@link Synset} instance contained in the database accessed by this {@link Uby} * instance.// w w w . j av a 2 s . co m * * @param externalSys * the {@link String} representing the name of external system such as: * OmegaWiki_2010-01-03_eng_definedMeaning WordNet_3.0_eng_synsetOffset * GermaNet_7.0_deu_synset * * @param externalRef * the Synset ID used in the external system, * * @returns the {@link Synset} specified by the given arguments */ public Synset getSynsetByOriginalReference(String externalSys, String externalRef) { Criteria criteria = session.createCriteria(Synset.class); criteria = criteria.createCriteria("monolingualExternalRefs").add(Restrictions.and( Restrictions.eq("externalSystem", externalSys), Restrictions.eq("externalReference", externalRef))); return (Synset) criteria.uniqueResult(); }
From source file:de.tudarmstadt.ukp.lmf.api.Uby.java
License:Apache License
/** * Returns the {@link Sense} instance contained in the database accessed by this {@link Uby} * instance. The returned senses are filtered by the given name of the external system, external * reference and lexicon./*from w ww.j av a 2 s. c o m*/ * * @return a {@link List} of all senses filtered by the given arguments or an empty list if one * of the given arguments is null or the accessed database does not contain any senses * matching both constraints. **/ public List<Sense> getSensesByOriginalReference(String externalSys, String externalRef, Lexicon lexicon) { Criteria criteria = session.createCriteria(Sense.class); criteria = criteria.createCriteria("monolingualExternalRefs").add(Restrictions.and( Restrictions.eq("externalSystem", externalSys), Restrictions.eq("externalReference", externalRef))); @SuppressWarnings("unchecked") List<Sense> result = criteria.list(); if (result == null) { result = new ArrayList<Sense>(0); } List<Sense> temp = new ArrayList<Sense>(result); for (Sense s : temp) { if (!s.getLexicalEntry().getLexicon().getName().equals(lexicon.getName())) { result.remove(s); } } return result; }
From source file:de.tudarmstadt.ukp.lmf.api.Uby.java
License:Apache License
/** * Returns a {@link List} of all {@link SemanticPredicate} instances in the * database with the given label and filtered by {@link Lexicon}. * @param label//from www . j av a2 s . c o m * semantic predicate label * @param lexicon * all returned semantic predicates will belong to * the specified lexicon * @return list of semantic predicates which matches the criteria or an * empty list if none of the semantic predicates matches the * criteria */ public List<SemanticPredicate> getSemanticPredicatesByLabelAndLexicon(String label, Lexicon lexicon) { System.err.println(lexicon.getId()); Criteria criteria = session.createCriteria(SemanticPredicate.class); criteria = criteria .add(Restrictions.and(Restrictions.eq("label", label), Restrictions.eq("lexicon", lexicon))); @SuppressWarnings("unchecked") List<SemanticPredicate> result = criteria.list(); if (result == null) { result = new ArrayList<SemanticPredicate>(0); } return result; }
From source file:de.tudarmstadt.ukp.lmf.api.Uby.java
License:Apache License
/** * Returns a {@link List} of all {@link SemanticArgument} instances in the * database with the given label and {@link SemanticPredicate}. * @param label//from ww w . j av a 2s. c o m * semantic argument label * @param lexicon * all returned semantic arguments will belong to * the specified lexicon * @return list of semantic predicates which matches the criteria or an * empty list if none of the semantic predicates matches the * criteria */ public List<SemanticArgument> getSemanticArgumentsByLabelAndPredicate(String roleLabel, SemanticPredicate predicate) { Criteria criteria = session.createCriteria(SemanticArgument.class); System.err.println(" predicateid " + predicate.getId()); criteria = criteria.add(Restrictions.and(Restrictions.eq("predicate", predicate), Restrictions.eq("semanticRole", roleLabel))); @SuppressWarnings("unchecked") List<SemanticArgument> result = criteria.list(); if (result == null) { result = new ArrayList<SemanticArgument>(0); } return result; }
From source file:depro.dao.PrecioDAOImpl.java
public Precio cargarPrecioPorPluYTienda(int idPlu, int idPuntoVenta) { Plu plu = new Plu(); plu.setIdPlu(idPlu);/*from www .jav a 2s . c om*/ PuntoVenta tienda = new PuntoVenta(); tienda.setIdPuntoVenta(idPuntoVenta); return findByAttributes( Restrictions.and(Restrictions.eq("plu", plu), Restrictions.eq("puntoVenta", tienda))); }
From source file:depro.dao.PrecioDAOImpl.java
public List<Precio> listarTodo(int tienda) { if (tienda < 1) { return findByCriteria(Restrictions.ge("precioPorKilo", 0)); } else {/*from w w w . j a v a 2 s .co m*/ return findByCriteria( Restrictions.and(Restrictions.ge("precioPorKilo", 0), Restrictions.ge("puntoVenta", tienda))); } }
From source file:dk.teachus.backend.dao.hibernate.HibernateStatisticsDAO.java
License:Apache License
@SuppressWarnings("unchecked") @Transactional(readOnly = true)/* w w w . jav a 2 s. co m*/ public List<PupilBooking> getAllBookings(DateMidnight fromDate, DateMidnight toDate) { DetachedCriteria c = DetachedCriteria.forClass(PupilBookingImpl.class); c.createCriteria("pupil").add(Restrictions.eq("active", true)); c.createCriteria("teacher").add(Restrictions.eq("active", true)); c.createCriteria("period").add(Restrictions.eq("status", Status.FINAL)); Disjunction disjunction = Restrictions.disjunction(); disjunction.add(Restrictions.and(Restrictions.ge("createDate", fromDate.toDateTime()), Restrictions.le("createDate", toDate.toDateTime()))); disjunction.add(Restrictions.and(Restrictions.ge("updateDate", fromDate.toDateTime()), Restrictions.le("updateDate", toDate.toDateTime()))); c.add(disjunction); c.setResultTransformer(DistinctRootEntityResultTransformer.INSTANCE); List<PupilBooking> bookings = getHibernateTemplate().findByCriteria(c); return bookings; }
From source file:dz.alkhwarizmix.framework.java.dao.impl.CustomDataDAO.java
License:Open Source License
/** */// ww w . j a v a 2s . c om @Override public CustomData getCustomData(CustomData customDataToGet) throws AlKhwarizmixException { getLogger().trace("getCustomData()"); try { final Criteria criteria = getHibernateCurrentSession().createCriteria(CustomData.class); final Criterion criter1 = Restrictions.eq(CustomData.CUSTOMDATAID, customDataToGet.getCustomDataId()); final Criterion criter2 = Restrictions.eq(CustomData.CUSTOMIZER, customDataToGet.getCustomizer().getId()); criteria.add(Restrictions.and(criter1, criter2)); customDataToGet = (CustomData) criteria.uniqueResult(); return customDataToGet; } catch (final DataAccessException e) { final AlKhwarizmixException ex = new AlKhwarizmixException(AlKhwarizmixErrorCode.ERROR_DATABASE, e); throw ex; } }