Search in sources :

Example 1 with QueryStructureReporter

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;
}
Also used : IStructureRecord(ambit2.base.interfaces.IStructureRecord) QueryStructureReporter(ambit2.db.reporters.QueryStructureReporter) PreparedStatement(java.sql.PreparedStatement) IQueryRetrieval(net.idea.modbcum.i.IQueryRetrieval) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) DbAmbitException(net.idea.modbcum.i.exceptions.DbAmbitException) SQLException(java.sql.SQLException) ProcessorException(ambit2.base.processors.ProcessorException) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) DbAmbitException(net.idea.modbcum.i.exceptions.DbAmbitException)

Aggregations

IStructureRecord (ambit2.base.interfaces.IStructureRecord)1 ProcessorException (ambit2.base.processors.ProcessorException)1 QueryStructureReporter (ambit2.db.reporters.QueryStructureReporter)1 PreparedStatement (java.sql.PreparedStatement)1 SQLException (java.sql.SQLException)1 IQueryRetrieval (net.idea.modbcum.i.IQueryRetrieval)1 AmbitException (net.idea.modbcum.i.exceptions.AmbitException)1 DbAmbitException (net.idea.modbcum.i.exceptions.DbAmbitException)1