Changeset 4119


Ignore:
Timestamp:
Feb 1, 2008, 4:31:53 PM (15 years ago)
Author:
Nicklas Nordborg
Message:

References #892: Abort long-running queries

Implemented a way to intterupt executing queries by redirecting all query activity through QueryExecutor?. This class uses features from the java.util.concurrent package. Currently, we only use this with queries against the dynamic database. It should not be very difficult to add support for Hibernate queries as well, but I don't know if there is any need for the extra overhead, since most of the time the Hibernate queries doesn't take long time.

The current implementation uses a simple unbounded thread pool. In the future, we should consider adding some configuration options for this.

Location:
trunk/src
Files:
1 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/net/sf/basedb/core/AbstractSqlQuery.java

    r3679 r4119  
    2929import net.sf.basedb.core.query.QueryType;
    3030import net.sf.basedb.core.query.Select;
     31import net.sf.basedb.core.signal.SignalException;
    3132
    3233import java.util.List;
     
    111112      Connection c = HibernateUtil.getConnection(dc.getHibernateSession());
    112113      if (debugSqlEnabled) logSql.debug("Executing count query: " + countSql);
    113       PreparedStatement ps = c.prepareStatement(countSql);
     114      final PreparedStatement ps = c.prepareStatement(countSql);
    114115      setParameters(ps, countParameterOrder);
    115       ResultSet result = ps.executeQuery();
     116     
     117      ResultSet result = QueryExecutor.executeQuery(ps);
     118
    116119      result.next();
    117120      totalCount = result.getInt(1);
     
    119122      ps.close();
    120123    }
     124    catch (InterruptedException ex)
     125    {
     126      throw new SignalException("Aborted by user", ex);
     127    }
    121128    catch (SQLException ex)
    122129    {
     
    184191      PreparedStatement ps = c.prepareStatement(sql);
    185192      setParameters(ps, parameterOrder);
    186       result = ps.executeQuery();
     193      result = QueryExecutor.executeQuery(ps);
    187194      if ((getFirstResult() > 0) && !HibernateUtil.getDialect().supportsLimitOffset())
    188195      {
    189196        result.absolute(getFirstResult());
    190197      }
     198    }
     199    catch (InterruptedException ex)
     200    {
     201      throw new SignalException("Aborted by user.", ex);
    191202    }
    192203    catch (SQLException ex)
     
    351362    }
    352363  }
     364 
    353365}
  • trunk/src/core/net/sf/basedb/core/Application.java

    r4117 r4119  
    425425     
    426426      // Initialise other utility classes
     427      QueryExecutor.init();
    427428      HibernateUtil.init1();
    428429      ExtendedProperties.init();
     
    588589    RawDataUtil.unload();
    589590    RawDataTypes.unload();
     591    QueryExecutor.unload();
    590592    ExtendedProperties.unload();
    591593    Config.unload();
  • trunk/src/core/net/sf/basedb/core/FeatureBatcher.java

    r4097 r4119  
    3131import net.sf.basedb.core.data.ReporterData;
    3232import net.sf.basedb.core.data.WellData;
     33import net.sf.basedb.core.signal.SignalException;
    3334
    3435import java.sql.PreparedStatement;
     
    328329      PreparedStatement ps = HibernateUtil.getConnection(getDbControl().getHibernateSession()).prepareStatement(sql);
    329330      ps.setInt(1, arrayDesign.getId());
    330       ps.executeUpdate();
     331      QueryExecutor.executeUpdate(ps);
    331332      arrayDesignData.setHasFeatures(false);
     333    }
     334    catch (InterruptedException ex)
     335    {
     336      throw new SignalException("Aborted by user.", ex);
    332337    }
    333338    catch (SQLException ex)
  • trunk/src/core/net/sf/basedb/core/FilterBatcher.java

    r3775 r4119  
    2828import net.sf.basedb.core.query.Expressions;
    2929import net.sf.basedb.core.query.Selects;
     30import net.sf.basedb.core.signal.SignalException;
    3031
    3132import java.util.List;
     
    324325      PreparedStatement ps =  HibernateUtil.getConnection(getDbControl().getHibernateSession()).prepareStatement(insertSql);
    325326      query.setParameters(ps, parameterOrder);
    326       rowsInserted = ps.executeUpdate();
     327      rowsInserted = QueryExecutor.executeUpdate(ps);
    327328      ps.close();
    328329      bytes += rowsInserted * bytesPerRow;
    329330      totalInsertCount += rowsInserted;
     331    }
     332    catch (InterruptedException ex)
     333    {
     334      throw new SignalException("Aborted by user.", ex);
    330335    }
    331336    catch (SQLException ex)
  • trunk/src/core/net/sf/basedb/core/MappingBatcher.java

    r3775 r4119  
    2929import net.sf.basedb.core.query.Expressions;
    3030import net.sf.basedb.core.query.Selects;
     31import net.sf.basedb.core.signal.SignalException;
    3132
    3233import java.util.List;
     
    256257      PreparedStatement ps =  HibernateUtil.getConnection(getDbControl().getHibernateSession()).prepareStatement(insertSql);
    257258      query.setParameters(ps, parameterOrder);
    258       rowsInserted = ps.executeUpdate();
     259      rowsInserted = QueryExecutor.executeUpdate(ps);
    259260      ps.close();
    260261      bytes += rowsInserted * bytesPerRow;
    261262      totalInsertCount += rowsInserted;
     263    }
     264    catch (InterruptedException ex)
     265    {
     266      throw new SignalException("Aborted by user.", ex);
    262267    }
    263268    catch (SQLException ex)
  • trunk/src/core/net/sf/basedb/core/PositionBatcher.java

    r3775 r4119  
    2929import net.sf.basedb.core.query.Expressions;
    3030import net.sf.basedb.core.query.Selects;
     31import net.sf.basedb.core.signal.SignalException;
    3132
    3233import java.util.List;
     
    252253      PreparedStatement ps =  HibernateUtil.getConnection(getDbControl().getHibernateSession()).prepareStatement(insertSql);
    253254      query.setParameters(ps, parameterOrder);
    254       rowsInserted = ps.executeUpdate();
     255      rowsInserted = QueryExecutor.executeUpdate(ps);
    255256      ps.close();
    256257      bytes += rowsInserted * bytesPerRow;
    257258      totalInsertCount += rowsInserted;
     259    }
     260    catch (InterruptedException ex)
     261    {
     262      throw new SignalException("Aborted by user.", ex);
    258263    }
    259264    catch (SQLException ex)
  • trunk/src/core/net/sf/basedb/core/PositionExtraValueBatcher.java

    r4020 r4119  
    2828import net.sf.basedb.core.query.Expressions;
    2929import net.sf.basedb.core.query.Selects;
     30import net.sf.basedb.core.signal.SignalException;
    3031
    3132import java.util.List;
     
    359360      PreparedStatement ps =  HibernateUtil.getConnection(getDbControl().getHibernateSession()).prepareStatement(insertSql);
    360361      query.setParameters(ps, parameterOrder);
    361       rowsInserted = ps.executeUpdate();
     362      rowsInserted = QueryExecutor.executeUpdate(ps);
    362363      ps.close();
    363364      bytes += rowsInserted * bytesPerRow;
    364365      totalInsertCount += rowsInserted;
     366    }
     367    catch (InterruptedException ex)
     368    {
     369      throw new SignalException("Aborted by user.", ex);
    365370    }
    366371    catch (SQLException ex)
  • trunk/src/core/net/sf/basedb/core/SpotBatcher.java

    r3775 r4119  
    2828import net.sf.basedb.core.query.Expressions;
    2929import net.sf.basedb.core.query.Selects;
     30import net.sf.basedb.core.signal.SignalException;
    3031
    3132import java.util.List;
     
    340341      PreparedStatement ps =  HibernateUtil.getConnection(getDbControl().getHibernateSession()).prepareStatement(insertSql);
    341342      query.setParameters(ps, parameterOrder);
    342       rowsInserted = ps.executeUpdate();
     343      rowsInserted = QueryExecutor.executeUpdate(ps);
    343344      ps.close();
    344345      bytes += rowsInserted * bytesPerRow;
    345346      totalInsertCount += rowsInserted;
     347    }
     348    catch (InterruptedException ex)
     349    {
     350      throw new SignalException("Aborted by user.", ex);
    346351    }
    347352    catch (SQLException ex)
  • trunk/src/core/net/sf/basedb/core/SpotExtraValueBatcher.java

    r4023 r4119  
    2828import net.sf.basedb.core.query.Expressions;
    2929import net.sf.basedb.core.query.Selects;
     30import net.sf.basedb.core.signal.SignalException;
    3031
    3132import java.util.List;
     
    347348      PreparedStatement ps =  HibernateUtil.getConnection(getDbControl().getHibernateSession()).prepareStatement(insertSql);
    348349      query.setParameters(ps, parameterOrder);
    349       rowsInserted = ps.executeUpdate();
     350      rowsInserted = QueryExecutor.executeUpdate(ps);
    350351      ps.close();
    351352      bytes += rowsInserted * bytesPerRow;
    352353      totalInsertCount += rowsInserted;
     354    }
     355    catch (InterruptedException ex)
     356    {
     357      throw new SignalException("Aborted by user.", ex);
    353358    }
    354359    catch (SQLException ex)
  • trunk/src/core/net/sf/basedb/core/VirtualDb.java

    r4023 r4119  
    2828import net.sf.basedb.core.data.VirtualDbData;
    2929import net.sf.basedb.core.data.SharedData;
     30import net.sf.basedb.core.signal.SignalException;
    3031
    3132import java.sql.Connection;
     
    345346          delete = c.prepareStatement(sql);
    346347          delete.setShort(1, cubeNo);
    347           rowsDeleted += delete.executeUpdate();
     348          rowsDeleted += QueryExecutor.executeUpdate(delete);
     349        }
     350        catch (InterruptedException ex)
     351        {
     352          throw new SignalException("Aborted by user.", ex);
    348353        }
    349354        catch (SQLException ex)
     
    392397        delete.setShort(1, cubeNo);
    393398        delete.setShort(2, layerNo);
    394         rowsDeleted += delete.executeUpdate();
     399        rowsDeleted += QueryExecutor.executeUpdate(delete);
     400      }
     401      catch (InterruptedException ex)
     402      {
     403        throw new SignalException("Aborted by user.", ex);
    395404      }
    396405      catch (SQLException ex)
     
    438447        delete.setShort(1, cubeNo);
    439448        delete.setShort(2, filterNo);
    440         rowsDeleted += delete.executeUpdate();
     449        rowsDeleted += QueryExecutor.executeUpdate(delete);
     450      }
     451      catch (InterruptedException ex)
     452      {
     453        throw new SignalException("Aborted by user.", ex);
    441454      }
    442455      catch (SQLException ex)
     
    485498        delete.setShort(1, cubeNo);
    486499        delete.setShort(2, extraNo);
    487         rowsDeleted += delete.executeUpdate();
     500        rowsDeleted += QueryExecutor.executeUpdate(delete);
     501      }
     502      catch (InterruptedException ex)
     503      {
     504        throw new SignalException("Aborted by user.", ex);
    488505      }
    489506      catch (SQLException ex)
  • trunk/src/plugins/core/net/sf/basedb/plugins/LowessNormalization.java

    r4118 r4119  
    445445       
    446446        DynamicResultIterator it = query.iterate(dc);
    447         checkInterrupted();
    448447        int positionIndex = it.getIndex(VirtualColumn.POSITION.getName());
    449448        int ch1Index = it.getIndex("ch1");
     
    455454        while (it.hasNext())
    456455        {
     456          checkInterrupted();
    457457          SqlResult r = it.next();
    458458          SpotData spot = new SpotData(r.getInt(positionIndex),
     
    462462        }
    463463        it.close();
    464         checkInterrupted();
    465464       
    466465        // Continue with next bioassay if there is no data
     
    496495            Collections.sort(toNormalize);
    497496            List<Double> smoothCurve = lowess(toNormalize, fitFraction, iterations, delta);
    498             checkInterrupted();
    499497            for (int j = 0; j < smoothCurve.size(); ++j)
    500498            {
     499              checkInterrupted();
    501500              SpotData spot = toNormalize.get(j);
    502501              double factor = Math.exp(smoothCurve.get(j) * 0.5);
    503502              batcher.insert(bioassayColumn, spot.position, (float)(spot.ch1/factor), (float)(spot.ch2*factor));
    504503            }
    505             checkInterrupted();
    506504            normalizedSpots += smoothCurve.size();
    507505            if (progress != null) progress.display((int)((normalizedSpots * 100L) / numSpots), normalizedSpots + " spots normalized");
Note: See TracChangeset for help on using the changeset viewer.