use of ambit2.db.readers.RetrieveDatasets in project ambit-mirror by ideaconsult.
the class DatasetsByStructureResource method createQuery.
@Override
protected IQueryRetrieval<SourceDataset> createQuery(Context context, Request request, Response response) throws ResourceException {
try {
Form form = request.getResourceRef().getQueryAsForm();
headless = Boolean.parseBoolean(form.getFirstValue("headless"));
} catch (Exception x) {
headless = false;
}
int idcompound = -1;
int idstructure = -1;
try {
idcompound = OpenTox.URI.compound.getIntValue(getRequest());
try {
idstructure = OpenTox.URI.conformer.getIntValue(getRequest());
} catch (Exception x) {
idstructure = -1;
}
} catch (Exception x) {
throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, OpenTox.URI.compound.getKey());
}
IStructureRecord record = new StructureRecord(idcompound, idstructure, null, null);
RetrieveDatasets q = new RetrieveDatasets();
q.setFieldname(record);
return q;
}
use of ambit2.db.readers.RetrieveDatasets in project ambit-mirror by ideaconsult.
the class RetrieveDatasetsTest method testGetDatasetbyChemical.
@Test
public void testGetDatasetbyChemical() throws Exception {
setUpDatabaseFromResource(getTestDatabase());
IDatabaseConnection c = getConnection();
ITable names = c.createQueryTable("EXPECTED_DATASETS", "SELECT * FROM src_dataset where name='Dataset 1'");
Assert.assertEquals(1, names.getRowCount());
QueryExecutor<RetrieveDatasets> qe = new QueryExecutor<RetrieveDatasets>();
qe.setConnection(c.getConnection());
IStructureRecord record = new StructureRecord();
record.setIdchemical(29141);
((RetrieveDatasets) query).setFieldname(record);
ResultSet rs = qe.process((RetrieveDatasets) query);
int count = 0;
while (rs.next()) {
ISourceDataset dataset = query.getObject(rs);
names = c.createQueryTable("EXPECTED_DATASETS", "SELECT * FROM src_dataset where id_srcdataset=" + dataset.getID() + " and name='" + dataset.getName() + "'");
Assert.assertEquals(1, names.getRowCount());
count++;
}
Assert.assertEquals(2, count);
rs.close();
qe.close();
c.close();
}
use of ambit2.db.readers.RetrieveDatasets in project ambit-mirror by ideaconsult.
the class RetrieveDatasetsTest method testGetObject.
@Test
public void testGetObject() throws Exception {
setUpDatabaseFromResource(getTestDatabase());
IDatabaseConnection c = getConnection();
ITable names = c.createQueryTable("EXPECTED_DATASETS", "SELECT * FROM src_dataset");
Assert.assertEquals(3, names.getRowCount());
QueryExecutor<RetrieveDatasets> qe = new QueryExecutor<RetrieveDatasets>();
qe.setConnection(c.getConnection());
ResultSet rs = qe.process((RetrieveDatasets) query);
while (rs.next()) {
ISourceDataset dataset = query.getObject(rs);
names = c.createQueryTable("EXPECTED_DATASETS", "SELECT * FROM src_dataset where id_srcdataset=" + dataset.getID() + " and name='" + dataset.getName() + "'");
Assert.assertEquals(1, names.getRowCount());
}
rs.close();
qe.close();
c.close();
}
use of ambit2.db.readers.RetrieveDatasets in project ambit-mirror by ideaconsult.
the class RetrieveDatasetsTest method testGetDatasetbyStructure.
@Test
public void testGetDatasetbyStructure() throws Exception {
setUpDatabaseFromResource(getTestDatabase());
IDatabaseConnection c = getConnection();
ITable names = c.createQueryTable("EXPECTED_DATASETS", "SELECT * FROM src_dataset where name='Dataset 1'");
Assert.assertEquals(1, names.getRowCount());
QueryExecutor<RetrieveDatasets> qe = new QueryExecutor<RetrieveDatasets>();
qe.setConnection(c.getConnection());
IStructureRecord record = new StructureRecord();
record.setIdstructure(129345);
((RetrieveDatasets) query).setFieldname(record);
ResultSet rs = qe.process((RetrieveDatasets) query);
int count = 0;
while (rs.next()) {
ISourceDataset dataset = query.getObject(rs);
names = c.createQueryTable("EXPECTED_DATASETS", "SELECT * FROM src_dataset where id_srcdataset=" + dataset.getID() + " and name='" + dataset.getName() + "'");
Assert.assertEquals(1, names.getRowCount());
count++;
}
Assert.assertEquals(2, count);
rs.close();
qe.close();
c.close();
}
use of ambit2.db.readers.RetrieveDatasets in project ambit-mirror by ideaconsult.
the class RetrieveDatasetsTest method testGetObjectByName.
@Test
public void testGetObjectByName() throws Exception {
setUpDatabaseFromResource(getTestDatabase());
IDatabaseConnection c = getConnection();
ITable names = c.createQueryTable("EXPECTED_DATASETS", "SELECT * FROM src_dataset where name='Dataset 1'");
Assert.assertEquals(1, names.getRowCount());
QueryExecutor<RetrieveDatasets> qe = new QueryExecutor<RetrieveDatasets>();
qe.setConnection(c.getConnection());
((RetrieveDatasets) query).setValue(new SourceDataset("Dataset 1"));
ResultSet rs = qe.process((RetrieveDatasets) query);
while (rs.next()) {
ISourceDataset dataset = query.getObject(rs);
names = c.createQueryTable("EXPECTED_DATASETS", "SELECT * FROM src_dataset where id_srcdataset=" + dataset.getID() + " and name='" + dataset.getName() + "'");
Assert.assertEquals(1, names.getRowCount());
}
rs.close();
qe.close();
c.close();
}
Aggregations