List of usage examples for org.hibernate.criterion DetachedCriteria forClass
public static DetachedCriteria forClass(Class clazz)
From source file:GCTestClient.java
License:BSD License
/** * Use case : Basic Genomic ID Search /*from w ww . j a v a 2 s . c o m*/ * Search on one more attribute within a Gene,MessengerRNA or Protein and * return result from that search as a list of objects of the same class * * Query in this Method: * Search on Gene where ensemblGeneId='ENS2' and get associated MessengerRNA * and print GenbankAccession. * */ static void querySimple() throws Exception { /** * Create a DetachedCriteria for Gene with ensemblGeneId=ENS2 */ DetachedCriteria geneCriteria = DetachedCriteria.forClass(Gene.class); geneCriteria.add(Restrictions.eq("ensemblGeneId", "ENS2")); List resultList = appService.query(geneCriteria, Gene.class.getName()); for (Iterator iter1 = resultList.iterator(); iter1.hasNext();) { /** get Gene Object form resultList*/ Gene gene = (Gene) iter1.next(); System.out.println("EnsemblGeneId : " + gene.getEnsemblGeneId()); /** get associated mRNAColelction from Gene*/ Collection coll = gene.getMessengerRNACollection(); for (Iterator iter = coll.iterator(); iter.hasNext();) { MessengerRNA mrna = (MessengerRNA) iter.next(); /** Print value of GenbankAccession attribute of MessengerRNA object */ System.out.println("GenbankAccession : " + mrna.getGenbankAccession()); } } }
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 w w .java 2 s .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
/** * @throws Exception/*from ww w. j a va 2 s .c o m*/ */ static void querybyNodeTraversal() throws Exception { /*Detached Criteria for GenomicIdentifier Set object*/ DetachedCriteria genomicIdSetCriteria = DetachedCriteria.forClass(GenomicIdentifierSet.class); /** * Create criteria for ONT where Set should contain a ONT as * EnsemblGene ---Direct---> Entrez Gene ---Direct---> UniGene * and optionally can also specify link type between each data source pair. */ /** * Create criteria for ONT as: * EnsemblGene ---Direct */ DetachedCriteria ontCrit = genomicIdSetCriteria.createCriteria("orderOfNodeTraversalCollection"); DetachedCriteria ontCritF = ontCrit.createCriteria("sourceDataSource") .add(Restrictions.eq("name", "Ensembl Gene")); ontCrit.createCriteria("linkType").add(Restrictions.eq("type", "DIRECT")); /** * Create criteria for ONT as: * EnsemblGene ---Direct---> Entrez Gene ---Direct */ DetachedCriteria ontCritF1 = ontCrit.createCriteria("childOrderOfNodeTraversal"); ontCritF1.createCriteria("sourceDataSource").add(Restrictions.eq("name", "Entrez Gene")); ontCritF1.createCriteria("linkType").add(Restrictions.eq("type", "DIRECT")); /** * Create criteria for ONT as: * EnsemblGene ---Direct---> Entrez Gene ---Direct---> UniGene */ DetachedCriteria ontCritF2 = ontCritF1.createCriteria("childOrderOfNodeTraversal"); DetachedCriteria ontCritF3 = ontCritF2.createCriteria("sourceDataSource"); ontCritF3.add(Restrictions.eq("name", "UniGene")); ontCritF2.add(Restrictions.isNull("childOrderOfNodeTraversal")); /** * Create Critria for ensemblTranscriptId = ENST1 AND * ensemblGeneAsOutput = true AND ensemblPeptideAsOutput = true */ DetachedCriteria mrnaCriteria = genomicIdSetCriteria.createCriteria("messengerRNA"); mrnaCriteria.add(Restrictions.eq("ensemblTranscriptId", "ENST1")); DetachedCriteria geneCriteria = genomicIdSetCriteria.createCriteria("gene"); geneCriteria.add(Restrictions.eq("ensemblGeneAsOutput", new Boolean(true))); DetachedCriteria proteinCriteria = genomicIdSetCriteria.createCriteria("protein"); proteinCriteria.add(Restrictions.eq("ensemblPeptideAsOutput", new Boolean(true))); // load all GenomicIdentifierSet objects with Gene.entrezgeneID = A1 and ONT A->C->D->B 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(); System.out.println("**************************************************************"); System.out.println("Set id: " + gset.getId() + " Confidence Score: " + gset.getConfidenceScore()); // System.out.println("Gid: " + gset.getGene().getEntrezgeneID()); Collection coll = gset.getOrderOfNodeTraversalCollection(); /*Get and Print the Order of Node Traveersal associated with this GenomicIdentifierSet*/ System.out.println("________________________________________________________"); for (Iterator iter1 = coll.iterator(); iter1.hasNext();) { System.out.println("ONT Id----DataSource-------LinkType"); OrderOfNodeTraversal ont = (OrderOfNodeTraversal) iter1.next(); OrderOfNodeTraversal tempont = ont; while (tempont != null) { LinkType ltype = tempont.getLinkType(); String linkType = null; if (ltype != null) linkType = ltype.getType(); System.out.println(tempont.getId() + "----" + tempont.getSourceDataSource().getName() + "------" + linkType); OrderOfNodeTraversal nextont = tempont.getChildOrderOfNodeTraversal(); tempont = nextont; } System.out.println("________________________________________________________"); } 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 w w . j a v a 2s. c o m * * 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 {// ww w . ja va 2s. c o 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
/** * This example demonstrates the use of Hibernate detached criteria objects * to formulate and perform more sophisticated searches. for more * information, please consult the Hibernate documentation at * http://www.hibernate.org/hib_docs/v3/api/org/hibernate/criterion/DetachedCriteria.html *//*from w w w. j av a2 s. c om*/ @SuppressWarnings("unused") private static void searchSNPAnnoation() { DetachedCriteria criteria = DetachedCriteria.forClass(SNPAnnotation.class); criteria.add(Restrictions.ge("chromosomeLocation", new Integer(4000000))); criteria.add(Restrictions.le("chromosomeLocation", new Integer(4200000))); criteria.add(Restrictions.eq("chromosomeName", "1")); try { System.out.println("______________________________________________________________________"); System.out.println("Retrieving all SNPAnnotations for Chr 1,4000000 - 4200000"); ApplicationService appService = ApplicationServiceProvider.getApplicationService(); List resultList = appService.query(criteria, SNPAnnotation.class.getName()); if (resultList != null) { System.out.println("Number of results returned: " + resultList.size()); System.out.println("DbsnpId" + "\t" + "ChromosomeName" + "\t" + "ChromosomeLocation" + "\t" + "GenomeBuild" + "\t" + "ReferenceSequence" + "\t" + "ReferenceStrand" + "\t" + "GeneBiomarker(s)" + "\n"); for (Iterator resultsIterator = resultList.iterator(); resultsIterator.hasNext();) { SNPAnnotation returnedObj = (SNPAnnotation) resultsIterator.next(); System.out.println(returnedObj.getDbsnpId() + "\t" + returnedObj.getChromosomeName() + "\t" + returnedObj.getChromosomeLocation() + "\t" + returnedObj.getGenomeBuild() + "\t" + returnedObj.getReferenceSequence() + "\t" + returnedObj.getReferenceStrand() + "\t" + pipeGeneBiomarkers(returnedObj.getGeneBiomarkerCollection()) + "\n"); } } } catch (Exception e) { e.printStackTrace(); } }
From source file:TestClientWithTimestamps.java
License:BSD License
@SuppressWarnings({ "unused", "unchecked" }) private static void searchGeneBiomarker() { /*/* ww w . j a v a 2 s. 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 w w w . jav a 2s . com 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:$.UserServiceImpl.java
License:Apache License
public List<User> listUser(User user) { DetachedCriteria detachedCriteria = DetachedCriteria.forClass(User.class); detachedCriteria.add(Restrictions.eq("user", user)); detachedCriteria.addOrder(Order.asc("id")); return userDao.findByCriteria(detachedCriteria); }/* w w w .ja v a 2 s. co m*/
From source file:aplicacion.datos.hibernate.dao.imp.GuiaPrecioDAOImpl.java
public ArrayList<GuiaPrecio> getGuias() { DetachedCriteria criteria = DetachedCriteria.forClass(GuiaPrecio.class); return (ArrayList) getHibernateTemplate().findByCriteria(criteria); // GuiaPrecio g1 = new GuiaPrecio(); // g1.setCodigo(1); // g1.setTipoVehiculo("Moto"); // g1.setPrecio(11.4); // resultado.add(g1); // GuiaPrecio g2 = new GuiaPrecio(); // g2.setCodigo(2); // g2.setTipoVehiculo("Auto"); // g2.setPrecio(25); // resultado.add(g2); //return resultado; }