Search in sources :

Example 1 with QueryCombined

use of ambit2.db.search.QueryCombined in project ambit-mirror by ideaconsult.

the class QueryCombinedTest method test.

@Test
public void test() throws Exception {
    ReadStoredQuery qs = new ReadStoredQuery();
    qs.setName("test");
    QueryCombined qc = new QueryCombinedStructure();
    qc.setId(55);
    QueryStructureByID q = new QueryStructureByID(100);
    q.setCondition(NumberCondition.getInstance("<="));
    Assert.assertNotNull(q.getParameters().get(1).getValue());
    qc.add(q);
    // between 150 and 200
    QueryStructureByID q1 = new QueryStructureByID(150, 200);
    Assert.assertNotNull(q1.getParameters().get(1).getValue());
    Assert.assertNotNull(q1.getParameters().get(3).getValue());
    qc.add(q1);
    qc.setCombine_as_and(false);
    /*
		Assert.assertEquals("select ? as idquery,idchemical,idstructure,if(type_structure='NA',0,1) as selected,? as metric,? as text from structure where idstructure <= ? order by type_structure desc\nunion\nselect ? as idquery,idchemical,idstructure,if(type_structure='NA',0,1) as selected,? as metric,? as text from structure where idstructure between  ? and ? order by type_structure desc",
				qc.getSQL());
		*/
    Assert.assertNotNull(q.getParameters().get(1).getValue());
    List<QueryParam> params = qc.getParameters();
    Assert.assertNotNull(params);
    Assert.assertEquals(9, params.size());
    Object[] values = { 55, 1, null, 100, 55, 1, null, 150, 200 };
    for (int i = 0; i < params.size(); i++) {
        if (values[i] != null) {
            Assert.assertEquals(Integer.class, params.get(i).getType());
            Assert.assertEquals(values[i], params.get(i).getValue());
        }
    }
    qc.setScope(qs);
/*
		qc.setScope(null);
		qc.setCombine_as_and(true);
		assertEquals("select Q1.idquery,s.idchemical,idstructure,Q1.selected as selected,Q1.metric as metric from structure as s\njoin\n(select ? as idquery,idchemical,idstructure,1 as selected,1 as metric from structure where idstructure <= ?)\nas Q1\nusing (idstructure)\njoin\n(select ? as idquery,idchemical,idstructure,1 as selected,1 as metric from structure where idstructure between ? and ?)\nas Q2\nusing (idstructure)",qc.getSQL());
		System.out.println(qc.getSQL());
		
		QueryStored qs = new QueryStored();
		qs.setName("test");
		
		qc.setScope(qs);
		System.out.println(qc.getSQL());
		*/
}
Also used : QueryParam(net.idea.modbcum.i.query.QueryParam) ReadStoredQuery(ambit2.db.update.storedquery.ReadStoredQuery) QueryCombined(ambit2.db.search.QueryCombined) QueryStructureByID(ambit2.db.search.structure.QueryStructureByID) QueryCombinedStructure(ambit2.db.search.structure.QueryCombinedStructure) Test(org.junit.Test)

Example 2 with QueryCombined

use of ambit2.db.search.QueryCombined in project ambit-mirror by ideaconsult.

the class QueryCombinedTest method testSelectBySmiles.

/**
 * gen = SmilesGenerator.unique().aromatic()
 * [Br-].[CH]:1:[CH]:[CH]:[C](:[CH]:[CH]1)[P+]([C]:2:[CH]:[CH]:[CH]:[CH]:[CH]2)([C]:3:[CH]:[CH]:[CH]:[CH]:[CH]3)CC
 * @throws Exception
 */
@Test
public void testSelectBySmiles() throws Exception {
    QueryCombined q = createQuery(ExactStructureSearchMode.smiles, "[Br-].c1ccc(cc1)[P+](c2ccccc2)(c3ccccc3)CC");
    q.setId(-1);
    setUpDatabaseFromResource(getDbFile());
    IDatabaseConnection c = getConnection();
    ResultSet rs = null;
    try {
        executor.setConnection(c.getConnection());
        executor.open();
        rs = executor.process(q);
        Assert.assertNotNull(rs);
        verify(q, rs);
    } finally {
        if (rs != null)
            rs.close();
        c.close();
    }
}
Also used : ResultSet(java.sql.ResultSet) QueryCombined(ambit2.db.search.QueryCombined) IDatabaseConnection(org.dbunit.database.IDatabaseConnection) Test(org.junit.Test)

Example 3 with QueryCombined

use of ambit2.db.search.QueryCombined in project ambit-mirror by ideaconsult.

the class QueryInfoTest method createQuery.

@Override
protected IQueryObject createQuery() throws Exception {
    QueryInfo info = new QueryInfo();
    QueryInfo.setFieldnames(fill_in());
    // info.setMolecule(MoleculeFactory.makeBenzene());
    info.setFieldname1("Field_1");
    info.setCondition1("=");
    info.setIdentifier1("20");
    info.setFieldname2("Field_2");
    info.setCondition2("=");
    info.setIdentifier2("40");
    info.setCombine(QueryInfo.COMBINE_ANY);
    info.setDataset(new SourceDataset("EINECS"));
    IAmbitEditor e = EditorPreferences.getEditor(info);
    assertNotNull(e);
    // JOptionPane.showMessageDialog(null,e.getJComponent());
    QueryInfo2Query processor = new QueryInfo2Query();
    IQueryObject query = processor.process(info);
    assertTrue(query instanceof QueryCombined);
    QueryCombined q = (QueryCombined) query;
    assertEquals(2, q.size());
    // first query
    assertTrue(q.get(0) instanceof QueryField);
    assertEquals("Field_1", ((QueryField) q.get(0)).getFieldname().getName());
    assertEquals("20", ((QueryField) q.get(0)).getValue());
    assertEquals(StringCondition.getInstance("="), ((QueryField) q.get(0)).getCondition());
    assertTrue(q.get(1) instanceof QueryField);
    assertEquals("Field_2", ((QueryField) q.get(1)).getFieldname());
    assertEquals("40", ((QueryField) q.get(1)).getValue());
    assertEquals(StringCondition.getInstance("="), ((QueryField) q.get(1)).getCondition());
    // scope
    assertNotNull(q.getScope());
    assertTrue(q.getScope() instanceof QueryDataset);
    QueryDataset d = (QueryDataset) q.getScope();
    assertEquals("EINECS", d.getValue().getName());
    System.out.println(q.getSQL());
    List<QueryParam> p = query.getParameters();
    for (int i = 0; i < p.size(); i++) {
        System.out.print(p.get(i).getType());
        System.out.print('\t');
        System.out.print(p.get(i).getValue());
        System.out.print('\n');
    }
    // fail("not implemented");
    return query;
}
Also used : QueryField(ambit2.db.search.structure.QueryField) IAmbitEditor(ambit2.base.interfaces.IAmbitEditor) QueryParam(net.idea.modbcum.i.query.QueryParam) SourceDataset(ambit2.base.data.SourceDataset) QueryDataset(ambit2.db.search.structure.QueryDataset) QueryCombined(ambit2.db.search.QueryCombined) QueryInfo(ambit2.db.search.QueryInfo) IQueryObject(net.idea.modbcum.i.IQueryObject) QueryInfo2Query(ambit2.db.processors.QueryInfo2Query)

Example 4 with QueryCombined

use of ambit2.db.search.QueryCombined in project ambit-mirror by ideaconsult.

the class QueryCombinedTest method createQuery.

protected QueryCombined createQuery(ExactStructureSearchMode mode, String value) throws Exception {
    QueryCombined q = new QueryCombinedStructure();
    QueryFieldNumeric d = new QueryFieldNumeric();
    d.setCondition(NumberCondition.getInstance(NumberCondition.between));
    d.setValue(new Double(10));
    d.setMaxValue(new Double(15));
    d.setFieldname(Property.getInstance("Property 1", "ref"));
    QueryStructure qf = new QueryStructure();
    qf.setFieldname(mode);
    qf.setValue(value);
    qf.setCondition(StringCondition.getInstance("="));
    q.setScope(null);
    q.setCombine_as_and(true);
    q.add(d);
    q.add(qf);
    return q;
}
Also used : QueryStructure(ambit2.db.search.structure.QueryStructure) QueryCombined(ambit2.db.search.QueryCombined) QueryFieldNumeric(ambit2.db.search.structure.QueryFieldNumeric) QueryCombinedStructure(ambit2.db.search.structure.QueryCombinedStructure)

Example 5 with QueryCombined

use of ambit2.db.search.QueryCombined in project ambit-mirror by ideaconsult.

the class QueryCombinedTest method testStructure.

@Test
public void testStructure() throws Exception {
    QueryCombined qc = new QueryCombinedStructure();
    qc.setId(55);
    QuerySimilarityBitset q = new QuerySimilarityBitset();
    FingerprintGenerator gen = new FingerprintGenerator(new Fingerprinter());
    BitSet bitset = gen.process(MoleculeFactory.makeAlkane(10));
    q.setValue(bitset);
    Assert.assertNotNull(q.getParameters().get(1).getValue());
    qc.add(q);
}
Also used : QuerySimilarityBitset(ambit2.db.search.structure.QuerySimilarityBitset) Fingerprinter(org.openscience.cdk.fingerprint.Fingerprinter) BitSet(java.util.BitSet) QueryCombined(ambit2.db.search.QueryCombined) FingerprintGenerator(ambit2.core.processors.structure.FingerprintGenerator) QueryCombinedStructure(ambit2.db.search.structure.QueryCombinedStructure) Test(org.junit.Test)

Aggregations

QueryCombined (ambit2.db.search.QueryCombined)6 QueryCombinedStructure (ambit2.db.search.structure.QueryCombinedStructure)4 Test (org.junit.Test)4 SourceDataset (ambit2.base.data.SourceDataset)2 QueryDataset (ambit2.db.search.structure.QueryDataset)2 QueryStructure (ambit2.db.search.structure.QueryStructure)2 QueryParam (net.idea.modbcum.i.query.QueryParam)2 IAmbitEditor (ambit2.base.interfaces.IAmbitEditor)1 FingerprintGenerator (ambit2.core.processors.structure.FingerprintGenerator)1 QueryInfo2Query (ambit2.db.processors.QueryInfo2Query)1 QueryInfo (ambit2.db.search.QueryInfo)1 QueryField (ambit2.db.search.structure.QueryField)1 QueryFieldNumeric (ambit2.db.search.structure.QueryFieldNumeric)1 QuerySimilarityBitset (ambit2.db.search.structure.QuerySimilarityBitset)1 QueryStructureByID (ambit2.db.search.structure.QueryStructureByID)1 ReadStoredQuery (ambit2.db.update.storedquery.ReadStoredQuery)1 ResultSet (java.sql.ResultSet)1 BitSet (java.util.BitSet)1 IQueryObject (net.idea.modbcum.i.IQueryObject)1 IDatabaseConnection (org.dbunit.database.IDatabaseConnection)1