/** * Runs the optimiser through the query, given the database. * * @param query the Query to optimise * @param database the database to use to find precomputed tables * @param context a QueryOptimiserContext, to alter settings * @return the optimised Query * @throws SQLException if a database error occurs */ protected static Query optimise(Query query, Database database, QueryOptimiserContext context) throws SQLException { return optimise(query.toString(), query, database, null, context).getBestQuery(); }
/** * Runs the optimiser through the query, given the database. * * @param query the Query to optimise * @param database the database to use to find precomputed tables * @param context a QueryOptimiserContext, to alter settings * @return the optimised Query * @throws SQLException if a database error occurs */ protected static Query optimise(Query query, Database database, QueryOptimiserContext context) throws SQLException { return optimise(query.toString(), query, database, null, context).getBestQuery(); }
public void testIsNotNullBugFails() throws Exception { String sql1 = "SELECT DISTINCT a2_.identifier AS a1_ FROM Gene AS a2_, Organism AS a3_ WHERE (a2_.organismId = a3_.id OR a2_.identifier IS NOT NULL) OR 'ENSANGG00000018976' < a2_.identifier ORDER BY a2_.identifier LIMIT 10000 OFFSET 1"; Query q1 = new Query(sql1); assertTrue(q1.toString().indexOf("IS NOT NULL") > 0); }
public void testIsNotNullBugWorks() throws Exception { String sql1 = "SELECT DISTINCT a2_.identifier AS a1_ FROM Gene AS a2_, Organism AS a3_ WHERE a2_.organismId = a3_.id OR a2_.identifier IS NOT NULL OR 'ENSANGG00000018976' < a2_.identifier ORDER BY a2_.identifier LIMIT 10000 OFFSET 1"; Query q1 = new Query(sql1); assertTrue(q1.toString().indexOf("IS NOT NULL") > 0); }
public void testWeirdBug1() throws Exception { String sql = "SELECT DISTINCT a1_.id AS a1_id, a4_.id AS a4_id, a6_.id AS a6_id, a8_.id AS a8_id, a7_.id AS a7_id, a14_.id AS a14_id, a9_.id AS a9_id, a10_.id AS a10_id, a12_.id AS a12_id, a1_.primaryIdentifier AS orderbyfield4, a4_.pubMedId AS orderbyfield5, a6_.name AS orderbyfield6, a8_.primaryIdentifier AS orderbyfield7, a7_.type AS orderbyfield8, a14_.title AS orderbyfield9, a9_.name AS orderbyfield10, a9_.observed AS orderbyfield11, a10_.pubMedId AS orderbyfield12, a12_.name AS orderbyfield13 " + "FROM Gene AS a1_, RNAiScreenHit AS a2_, RNAiScreen AS a3_, Publication AS a4_, DataSet AS a5_, DataSource AS a6_, Homologue AS a7_, Gene AS a8_, RNAiPhenotype AS a9_, Publication AS a10_, DataSet AS a11_, DataSource AS a12_, Organism AS a13_, DataSet AS a14_, Organism AS a15_, AnalysisResultDataSets AS indirect0, AnnotationPublications AS indirect1, AnalysisResultDataSets AS indirect2, DataSetsHomologue AS indirect3 " + "WHERE a1_.id = a2_.geneId AND LOWER(a2_.intermine_result) NOT LIKE 'not screened' AND a2_.rnaiScreenId = a3_.id AND a3_.publicationId = a4_.id AND a2_.id = indirect0.DataSets AND indirect0.AnalysisResult = a5_.id AND a5_.dataSourceId = a6_.id AND a1_.id = a7_.geneId AND a7_.homologueId = a8_.id AND a8_.id = a9_.subjectId AND a9_.id = indirect1.Publications AND indirect1.Annotation = a10_.id AND a9_.id = indirect2.DataSets AND indirect2.AnalysisResult = a11_.id AND a11_.dataSourceId = a12_.id AND a8_.organismId = a13_.id AND LOWER(a13_.name) LIKE 'caenorhabditis elegans' AND LOWER(a7_.type) LIKE 'orthologue' AND a7_.id = indirect3.DataSets AND indirect3.Homologue = a14_.id AND a1_.organismId = a15_.id AND LOWER(a15_.name) LIKE 'drosophila melanogaster' AND a1_.id = 355180125 " + "ORDER BY a1_.primaryIdentifier, a4_.pubMedId, a6_.name, a8_.primaryIdentifier, a7_.type, a14_.title, a9_.name, a9_.observed, a10_.pubMedId, a12_.name, a1_.id, a4_.id, a6_.id, a8_.id, a7_.id, a14_.id, a9_.id, a10_.id, a12_.id LIMIT 1000"; Query q = new Query(sql); assertEquals(sql, q.toString()); }
public void testToString() throws Exception { String sql = "SELECT DISTINCT a1_.identifier AS a10_, a1_.primaryIdentifier AS a11_, " + "a1_.symbol AS a12_, a3_.primaryAccession AS " + "a14_, a8_.interproId AS a15_, a8_.identifier AS a16_, a8_.name AS a17_, " + "a8_.shortName AS a18_ FROM Gene AS a1_, Synonym AS a2_, Protein AS" + " a3_, ProteinRegion AS a4_, ProteinStructure AS a5_, ProteinRegion AS a6_, " + "Location AS a7_, ProteinFeature AS a8_, Organism AS a9_, GenesProteins AS " + "indirect0 WHERE LOWER(a2_.intermine_value) = 'cg1046' AND LOWER(a9_.name)" + " = 'drosophila melanogaster' AND a1_.id = a2_.subjectId AND a1_.id = " + "indirect0.Proteins AND indirect0.Genes = a3_.id AND a3_.id = a4_.proteinId " + "AND a4_.id = a5_.regionId AND a5_.regionId = a6_.id AND a6_.id = a7_.featureId " + "AND a6_.proteinFeatureId = a8_.id AND a1_.organismId = a9_.id ORDER BY " + "a1_.identifier, a1_.primaryIdentifier, a1_.symbol, " + "a3_.primaryAccession, a8_.interproId, a8_.identifier, a8_.name, a8_.shortName"; Query q1 = new Query(sql); assertEquals(sql, q1.toString()); }