use of ambit2.db.reporters.QueryStructureReporter in project ambit-mirror by ideaconsult.
the class ProcessorCreateQuery method insertScreenedResults.
protected int insertScreenedResults(IStoredQuery result, final IQueryRetrieval<IStructureRecord> query) throws SQLException, AmbitException {
final PreparedStatement insertGoodResults = connection.prepareStatement(IStoredQuery.SQL_INSERT + " values(?,?,?,1,?,?)");
QueryStructureReporter<IQueryRetrieval<IStructureRecord>, IStructureRecord> reporter = new QueryStructureReporter<IQueryRetrieval<IStructureRecord>, IStructureRecord>() {
@Override
public void close() throws Exception {
// TODO Auto-generated method stub
super.close();
}
@Override
public void header(IStructureRecord output, IQueryRetrieval<IStructureRecord> query) {
// TODO Auto-generated method stub
}
@Override
public Object processItem(IStructureRecord record) throws AmbitException {
try {
insertGoodResults.setInt(1, query.getId());
insertGoodResults.setInt(2, record.getIdchemical());
insertGoodResults.setInt(3, record.getIdstructure());
insertGoodResults.setDouble(4, 1);
insertGoodResults.setNull(5, Types.VARCHAR);
insertGoodResults.executeUpdate();
} catch (Exception x) {
throw new AmbitException(x);
}
return null;
}
public void open() throws DbAmbitException {
}
@Override
public void footer(IStructureRecord output, IQueryRetrieval<IStructureRecord> query) {
// TODO Auto-generated method stub
}
};
try {
long timeout = 8 * 1000;
try {
timeout = Long.parseLong(Preferences.getProperty(Preferences.TIMEOUT));
} catch (Exception x) {
}
// 1s
reporter.setTimeout(timeout);
reporter.setAutoCommit(true);
reporter.setConnection(connection);
reporter.process(query);
} catch (Exception x) {
logger.log(Level.WARNING, x.getMessage(), x);
} finally {
try {
insertGoodResults.close();
} catch (Exception x) {
logger.log(Level.FINEST, x.getMessage(), x);
}
try {
reporter.close();
} catch (Exception x) {
logger.log(Level.FINEST, x.getMessage(), x);
}
}
return 1;
}
Aggregations