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());
*/
}
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();
}
}
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;
}
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;
}
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);
}
Aggregations