Example usage for org.hibernate.criterion Restrictions gt

List of usage examples for org.hibernate.criterion Restrictions gt

Introduction

In this page you can find the example usage for org.hibernate.criterion Restrictions gt.

Prototype

public static SimpleExpression gt(String propertyName, Object value) 

Source Link

Document

Apply a "greater than" constraint to the named property

Usage

From source file:GCTestClient.java

License:BSD License

/**
 * Use case : Query Based on Confidence 
 * Search on one more attribute within a Gene,MessengerRNA or Protein class
 * with a given or higher confidence score (from GenomicIdentifierSet).
 * Traverse the model to get data from the other classes.
 *  //from   w  ww.  j a va2s.  c  o  m
 *  Query in this method:
 *  Search on Protein where ensemblGeneId='ENS2' AND unigene,ensemblPeptide as output 
 *  AND confidenceScore > 0.2
 *  Print Set ID,Confidenscore and associated Gene,mRNA values with this Set 
 *  
 */

static void queryConfScore() throws Exception {
    /**
     * Create Detached for GenomicIdentifierSet Object and add restriction on confidence score
     * confidenceScore>0.2
     */
    DetachedCriteria genomicIdSetCriteria = DetachedCriteria.forClass(GenomicIdentifierSet.class);
    genomicIdSetCriteria.add(Restrictions.gt("confidenceScore", new Float("0.1")));

    /**
     * Create Criteria for search on ensemblGeneId = ENS2 AND unigeneAsOutput = true
     * AND ensemblPeptideAsOutput=true
     */

    DetachedCriteria geneCriteria = genomicIdSetCriteria.createCriteria("gene");
    geneCriteria.add(Restrictions.eq("ensemblGeneId", "ENS2"));

    geneCriteria.add(Restrictions.eq("unigeneAsOutput", new Boolean(true)));

    DetachedCriteria proteinCriteria = genomicIdSetCriteria.createCriteria("protein");
    proteinCriteria.add(Restrictions.eq("ensemblPeptideAsOutput", new Boolean(true)));
    /**
     * Execute the Query
     */
    List resultList = appService.query(genomicIdSetCriteria,
            "edu.wustl.geneconnect.domain.GenomicIdentifierSet");
    System.out.println("Result Size: " + resultList.size());
    for (Iterator iter = resultList.iterator(); iter.hasNext();) {

        GenomicIdentifierSet gset = (GenomicIdentifierSet) iter.next();
        /**Print Set Id and Confidence Score*/
        System.out.println(
                "\nSet Id: " + gset.getId() + "  Confidence Score: " + gset.getConfidenceScore() + "\n");
        Gene gene = gset.getGene();
        MessengerRNA mrna = gset.getMessengerRNA();
        Protein protein = gset.getProtein();

        System.out.println("Ensembl Gene ID | UniGene cluster ID | Ensembl Peptide ID");
        System.out.println(gene.getEnsemblGeneId() + "           | " + gene.getUnigeneClusterId()
                + "            | " + protein.getEnsemblPeptideId());

        System.out
                .println("-----------------------------------------------------------------------------------");
    }
}

From source file:GCTestClient.java

License:BSD License

/**
 * Use case : Query By Limiting ID Frequency 
 * Search on one ensemblPeptideId attribute within a Protein 
 * with a given higher frequency (from GenomicIdentifierData) for Entrez Gene 
 * data source./*from   w  ww  . j a  va  2s  . com*/
 *  
 * Display the result contining Genomic IDs and associated Frequency
 *   
 * @throws Exception
 */
public static void queryByLimitingIDFrequency() throws Exception {

    /**
     * Create DetachedCriteria for GenomicIdentifierSet with restriction for confidenceScore >=0.2 
     */
    DetachedCriteria genomicIdSetCriteria = DetachedCriteria.forClass(GenomicIdentifierSet.class);

    /**
     * Create Criteria to search on guven frequency of given data source 
     */

    DetachedCriteria freqCriteria = genomicIdSetCriteria.createCriteria("consensusIdentifierDataCollection");

    freqCriteria.add(Restrictions.gt("frequency", new Float("0.1")));
    freqCriteria.add(Restrictions.gt("frequency", new Float("0.1")));

    /** 
     * The dataSource value should be one of the Data Source Name
     * 
     */
    DetachedCriteria genomicIdCriteria = freqCriteria.createCriteria("genomicIdentifier");

    genomicIdCriteria.add(Restrictions.eq("dataSource", "Ensembl Gene"));
    genomicIdCriteria.add(Restrictions.eq("dataSource", "Entrez Gene"));

    /**
     * Create Criteria for ensemblGene selected as ouput 
     */
    DetachedCriteria geneCriteria = genomicIdSetCriteria.createCriteria("gene");
    geneCriteria.add(Restrictions.eq("ensemblGeneAsOutput", new Boolean(true)));

    /**
     * Create Criteria for search on ensemblPeptideId attribute
     */
    DetachedCriteria proteinCriteria = genomicIdSetCriteria.createCriteria("protein");
    proteinCriteria.add(Restrictions.eq("ensemblPeptideId", "ENSP1"));

    /**
     * Create Criteria for refseqmRNA selected as ouput 
     */
    DetachedCriteria mranCriteria = genomicIdSetCriteria.createCriteria("messengerRNA");
    mranCriteria.add(Restrictions.eq("refseqmRNAAsOutput", new Boolean(true)));

    List resultList = appService.query(genomicIdSetCriteria, GenomicIdentifierSet.class.getName());
    System.out.println("ResultSet Size: " + resultList.size());

    for (Iterator iter = resultList.iterator(); iter.hasNext();) {
        GenomicIdentifierSet gset = (GenomicIdentifierSet) iter.next();
        /*Print Set Id and Confidence Score*/
        System.out.println(
                "\nSet Id: " + gset.getId() + "  Confidence Score: " + gset.getConfidenceScore() + "\n");
        Gene gene = gset.getGene();
        MessengerRNA mrna = gset.getMessengerRNA();
        Protein p = gset.getProtein();

        System.out.println("Ensembl Gene ID | Ensembl Peptide ID | RefSeq mRNA ID");
        System.out.println(gene.getEnsemblGeneId() + "           | " + p.getEnsemblPeptideId()
                + "            | " + mrna.getRefseqId());

        System.out
                .println("-----------------------------------------------------------------------------------");
    }
    /*
     * Print the Genomic identiifer and its frequency throughout the GenomicIdentifierSolution
     */
    System.out.println(
            "Following is  a list of all genomic identifers (occured in this result)and its frequency");
    if (resultList.size() > 0) {
        GenomicIdentifierSet set = (GenomicIdentifierSet) resultList.get(0);

        GenomicIdentifierSolution solution = set.getGenomicIdentifierSolution();
        Collection coll = solution.getConsensusIdentifierDataCollection();
        System.out.println("Genomic Identifer\tFrequency");
        for (Iterator iter1 = coll.iterator(); iter1.hasNext();) {
            //OrderOfNodeTraversal ont = (OrderOfNodeTraversal)iter1.next();
            ConsensusIdentifierData ont = (ConsensusIdentifierData) iter1.next();
            GenomicIdentifier g = ont.getGenomicIdentifier();
            if (g != null)
                System.out.println("\t" + g.getGenomicIdentifier() + "\t\t\t" + ont.getFrequency());
        }
    }
}

From source file:TechGuideExamples.java

License:BSD License

public static void main(String[] args) throws Exception {

    System.out.println("*** Tech Guide Examples");

    ApplicationService appService = ApplicationServiceProvider.getApplicationService();

    /** Examples used in Developer Guide */

    try {/*from  ww w  . j  ava2  s.  co  m*/
        System.out.println("\nExample One: Simple Search (Single Criteria Object)");
        Gene gene = new Gene();
        // searching for all genes whose symbol starts with brca
        gene.setSymbol("brca*");

        List resultList = appService.search(Gene.class, gene);

        for (Iterator resultsIterator = resultList.iterator(); resultsIterator.hasNext();) {
            Gene returnedGene = (Gene) resultsIterator.next();
            System.out.println("Symbol: " + returnedGene.getSymbol() + "\tTaxon:"
                    + returnedGene.getTaxon().getScientificName() + "\tName " + returnedGene.getFullName());
        }
    } catch (RuntimeException e) {
        e.printStackTrace();
    }

    try {
        System.out.println("\nExample Two: Simple Search (Criteria Object Collection)");
        Taxon taxon1 = new Taxon();
        taxon1.setAbbreviation("hs"); // Homo sapiens
        Taxon taxon2 = new Taxon();
        taxon2.setAbbreviation("m"); // Mus musculus
        List<Taxon> taxonList = new ArrayList<Taxon>();
        taxonList.add(taxon1);
        taxonList.add(taxon2);
        List resultList = appService.search(Gene.class, taxonList);
        System.out.println("Total # of records = " + resultList.size());

    } catch (Exception e) {
        e.printStackTrace();
    }

    try {
        System.out.println("\nExample Three: Simple Search (Compound Criteria Object)");
        Taxon taxon = new Taxon();
        taxon.setAbbreviation("hs"); // Homo sapiens
        Gene gene = new Gene();
        gene.setTaxon(taxon);
        gene.setSymbol("IL5"); // Interleukin 5
        List<Gene> geneList = new ArrayList<Gene>();
        geneList.add(gene);
        Pathway pathway = new Pathway();
        pathway.setGeneCollection(geneList);
        List resultList = appService.search("gov.nih.nci.cabio.domain.Pathway", pathway);
        for (Iterator resultsIterator = resultList.iterator(); resultsIterator.hasNext();) {
            Pathway returnedPathway = (Pathway) resultsIterator.next();
            System.out.println("Name: " + returnedPathway.getName() + "\tDisplayValue: "
                    + returnedPathway.getDisplayValue());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    try {
        System.out.println("\nExample Four: Nested Search");
        Gene gene = new Gene();
        gene.setSymbol("TP53"); // Tumor protein p53 (Li-Fraumeni syndrome)   
        List resultList = appService
                .search("gov.nih.nci.cabio.domain.ProteinSequence,gov.nih.nci.cabio.domain.Protein", gene);
        for (Iterator resultsIterator = resultList.iterator(); resultsIterator.hasNext();) {
            ProteinSequence returnedProtSeq = (ProteinSequence) resultsIterator.next();
            System.out.println("Id: " + returnedProtSeq.getId() + "\tLength: " + returnedProtSeq.getLength());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    try {
        System.out.println("\nExample Five: Detached Criteria Search");
        DetachedCriteria criteria = DetachedCriteria.forClass(PhysicalLocation.class);
        criteria = criteria.add(Restrictions.gt("chromosomalStartPosition", new Long(86851632)));
        criteria = criteria.add(Restrictions.lt("chromosomalEndPosition", new Long(86861632)));
        criteria = criteria.add(Restrictions.ilike("assembly", "reference"));
        criteria = criteria.createCriteria("chromosome").add(Restrictions.eq("number", "1"));
        List resultList = appService.query(criteria);
        System.out.println("Total # of  records = " + resultList.size());
    } catch (Exception e) {
        e.printStackTrace();
    }

    try {
        System.out.println("\nExample Six: HQL Search");
        String hqlString = "FROM gov.nih.nci.cabio.domain.Gene g WHERE g.symbol LIKE ?";
        List<String> params = new ArrayList<String>();
        params.add("BRCA%");
        HQLCriteria hqlC = new HQLCriteria(hqlString, params);
        List resultList = appService.query(hqlC);
        System.out.println("Total # of records = " + resultList.size());
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:TestClientWithTimestamps.java

License:BSD License

@SuppressWarnings({ "unused", "unchecked" })
private static void searchGeneBiomarker() {
    /*/*from ww w  . ja va2s . c om*/
     * This example demonstrates the use of Hibernate detached criteria
     * objects to formulate and perform more sophisticated searches. A
     * detailed description of detached criteria is beyond the scope of this
     * example; for more information, please consult the Hibernate
     * documentation at
     * http://www.hibernate.org/hib_docs/v3/api/org/hibernate/criterion/DetachedCriteria.html
     */

    DetachedCriteria criteria = DetachedCriteria.forClass(GeneBiomarker.class);
    criteria.add(Restrictions.gt("startPhyscialLocation", new Long(6000000)));
    criteria.add(Restrictions.lt("endPhysicalLocation", new Long(6300000)));
    criteria.add(Restrictions.eq("chromosome", "19"));

    try {
        System.out.println("______________________________________________________________________");
        System.out.println("Retrieving all GeneBiomarker objects for Chr 19,6000000 - 6300000");
        ApplicationService appService = ApplicationServiceProvider.getApplicationService();

        List resultList = appService.query(criteria, GeneBiomarker.class.getName());
        if (resultList != null) {
            System.out.println("Number of results returned: " + resultList.size());
            System.out.println("ChromosomeName" + "\t" + "StartPhyscialLocation" + "\t" + "EndPhysicalLocation"
                    + "\t" + "HugoGeneSymbol" + "\n");
            for (Iterator resultsIterator = resultList.iterator(); resultsIterator.hasNext();) {
                GeneBiomarker returnedObj = (GeneBiomarker) resultsIterator.next();
                System.out.println(returnedObj.getChromosome() + "\t" + returnedObj.getStartPhyscialLocation()
                        + "\t" + returnedObj.getEndPhysicalLocation() + "\t" + returnedObj.getHugoGeneSymbol()
                        + "\n");
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Example5.java

License:BSD License

private void testSearchSpecimen(ApplicationService appService) {

    DetachedCriteria criteria = DetachedCriteria.forClass(Specimen.class);
    criteria.add(Restrictions.gt("quantity", new Quantity("50")));

    try {//from www  . ja va  2s  .co m
        List resultList = appService.query(criteria, Specimen.class.getName());

        System.out.println("No of specimens found: " + resultList.size());
        for (Iterator resultsIterator = resultList.iterator(); resultsIterator.hasNext();) {
            Specimen returnedspecimen = (Specimen) resultsIterator.next();
            System.out.println(
                    "Label: " + returnedspecimen.getLabel() + "Type: " + returnedspecimen.getType() + " ");
            System.out.println("\tQuantity: " + returnedspecimen.getQuantity().getValue() + " ");
        }
    } catch (Exception e) {
        System.out.println(e.getMessage());
        e.printStackTrace();
    }
}

From source file:ar.com.zauber.commons.repository.query.visitor.CriteriaFilterVisitor.java

License:Apache License

/** calculate a criterion */
private Criterion createCriterion(final BinaryPropertyFilter binaryPropertyFilter, final Object value) {
    final String fieldName = getFieldName(binaryPropertyFilter.getProperty());
    final Criterion ret;

    if (binaryPropertyFilter instanceof EqualsPropertyFilter) {
        ret = Restrictions.eq(fieldName, value);
    } else if (binaryPropertyFilter instanceof LessThanPropertyFilter) {
        ret = Restrictions.lt(fieldName, value);
    } else if (binaryPropertyFilter instanceof LessThanEqualsPropertyFilter) {
        ret = Restrictions.le(fieldName, value);
    } else if (binaryPropertyFilter instanceof GreaterThanPropertyFilter) {
        ret = Restrictions.gt(fieldName, value);
    } else if (binaryPropertyFilter instanceof GreaterThanEqualsPropertyFilter) {
        ret = Restrictions.ge(fieldName, value);
    } else if (binaryPropertyFilter instanceof LikePropertyFilter) {
        if (((LikePropertyFilter) binaryPropertyFilter).getCaseSensitive()) {
            ret = Restrictions.like(fieldName, value);
        } else {// ww  w .  j  av  a2 s  . c om
            ret = Restrictions.ilike(fieldName, value);
        }
    } else {
        throw new IllegalStateException("Unable to process filter" + binaryPropertyFilter);
    }

    return ret;
}

From source file:at.molindo.esi4j.module.hibernate.scrolling.DefaultQueryScrollingSession.java

License:Apache License

@Override
public List<?> fetch(Session session, int batchSize) {
    Criteria criteria = session.createCriteria(_type);
    if (_lastId != null) {
        criteria.add(Restrictions.gt("id", _lastId));
    }//from  w  ww.j av a 2  s . com
    criteria.addOrder(Order.asc("id"));
    criteria.setMaxResults(batchSize);
    criteria.setCacheable(false);

    for (Map.Entry<String, FetchMode> e : _fetchModes.entrySet()) {
        criteria.setFetchMode(e.getKey(), e.getValue());
    }

    List<?> list = criteria.list();

    if (list.size() > 0) {
        ClassMetadata meta = session.getSessionFactory().getClassMetadata(_type);

        Object last = list.get(list.size() - 1);
        _lastId = meta.getIdentifier(last, (SessionImpl) session);
    }

    return list;
}

From source file:au.com.optus.mcas.sdp.bizservice.ott.ordertracking.batchjob.dao.impl.OttOrderActivityDaoImpl.java

License:Open Source License

/**
 * This method is used to retrieve OrderTrackingActivityDetails using the last success run
 * and return the list of OttOrderActivity objects.
 * @param lastSuccessRun/*from   w  w w.j av a  2 s.c o m*/
 *        Date
 * @return List
 */
public List<OttOrderActivity> retrieveOrderTrackingActivityDetails(Date lastSuccessRun) {
    LOG.info("retrieveOrderTrackingActivityDetails Method ----------- STARTS");
    List<OttOrderActivity> ottOrderActivityList = new ArrayList<OttOrderActivity>();
    if (lastSuccessRun != null) {
        DetachedCriteria criteria = super.createDetachedCriteria();
        Calendar c = Calendar.getInstance();
        c.setTime(lastSuccessRun);
        Date time = c.getTime();
        criteria.add(Restrictions.disjunction().add(Restrictions.eq("transitionTaskModifiedTime", time))
                .add(Restrictions.gt("transitionTaskModifiedTime", time)));

        ottOrderActivityList = findByCriteria(criteria);
        if (!ottOrderActivityList.isEmpty()) {
            LOG.debug("OttOrderActivityDaoImpl : retrieveOrderTrackingActivityDetails : "
                    + "Record found for lastSuccessRun " + lastSuccessRun
                    + " in OTT_ORDER_ACTIVITY_VIEW table");

        }

    }
    LOG.debug("OttOrderActivityDaoImpl : retrieveOrderTrackingActivityDetails : "
            + "Record not found for lastSuccessRun " + lastSuccessRun + " in OTT_ORDER_ACTIVITY_VIEW table");
    LOG.info("retrieveOrderTrackingActivityDetails Method ----------- ENDS");
    return ottOrderActivityList;

}

From source file:au.com.optus.mcas.sdp.bizservice.ott.ordertracking.batchjob.dao.impl.OttOrderSummaryDaoImpl.java

License:Open Source License

/**
 * This method is used the retrieve OrderTrackingSummaryDetails using last success run
 * and returns the list of OttOrderSummary object.
 * @param lastSuccessRun//from w  w w  . java 2 s.  com
 *         Date
 * @return List
 *
 */
public List<OttOrderSummary> retrieveOrderTrackingSummaryDetails(Date lastSuccessRun) {
    LOG.info("retrieveOrderTrackingSummaryDetails Method ----------- STARTS");
    List<OttOrderSummary> ottOrderSummaryList = new ArrayList<OttOrderSummary>();
    if (lastSuccessRun != null) {
        DetachedCriteria criteria = super.createDetachedCriteria();
        Calendar c = Calendar.getInstance();
        c.setTime(lastSuccessRun);
        criteria.add(Restrictions.disjunction().add(Restrictions.eq("orderModifiedDate", c.getTime()))
                .add(Restrictions.gt("orderModifiedDate", c.getTime()))
                .add(Restrictions.eq("orderCustomerModifiedDate", c.getTime()))
                .add(Restrictions.gt("orderCustomerModifiedDate", c.getTime())));

        ottOrderSummaryList = findByCriteria(criteria);
        if (!ottOrderSummaryList.isEmpty()) {
            LOG.debug("OttOrderSummaryDaoImpl : retrieveOrderTrackingSummaryDetails : "
                    + "Record found for lastSuccessRun " + lastSuccessRun + " in OTT_ORDER_SUMMARY_VIEW table");
            return ottOrderSummaryList;

        }
    }
    LOG.debug(
            "OttOrderSummaryDaoImpl : retrieveOrderTrackingSummaryDetails : Record not found for lastSuccessRun "
                    + lastSuccessRun + " in OTT_ORDER_SUMMARY_VIEW table");
    LOG.info("retrieveOrderTrackingSummaryDetails Method ----------- ENDS");
    return ottOrderSummaryList;

}

From source file:au.edu.uts.eng.remotelabs.schedserver.bookings.impl.slotsengine.DayBookings.java

License:Open Source License

/**
 * Adds a day range constraint to a bookings query so that bookings within
 * this day are returned.//  ww  w.  ja  va2  s  . c o m
 * 
 * @return restriction
 */
private Criterion addDayRange() {
    return Restrictions.disjunction().add(Restrictions.and( // Booking within day
            Restrictions.ge("startTime", this.dayBegin), Restrictions.le("endTime", this.dayEnd)))
            .add(Restrictions.and( // Booking starts before day and ends on this day
                    Restrictions.lt("startTime", this.dayBegin), Restrictions.gt("endTime", this.dayBegin)))
            .add(Restrictions.and( // Booking starts on day and ends after day
                    Restrictions.lt("startTime", this.dayEnd), Restrictions.gt("endTime", this.dayEnd)))
            .add(Restrictions.and(Restrictions.le("startTime", this.dayBegin),
                    Restrictions.gt("endTime", this.dayEnd)));
}