Пример #1
0
  /**
   * The run method for the thread that retrieves the data from the database. This method should not
   * be called directly. Instead use the retrieve method.
   */
  public void run() {
    try {
      DataStoreRow row = new DataStoreRow(this, new DSDataRow(_desc), _desc);

      while (_dataSource.retrieveRow(this, row)) {
        _rows.addElement(row.getDSDataRow());
        if (_threaded) notifyListeners(ModelChangedEvent.TYPE_ROW_INSERTED_OR_DELETED);

        if (!_retrieveInProgress || (_maxRows > -1 && _rows.size() >= _maxRows)) {
          _cancelInProgress = true;
          _retrieveInProgress = false;
          interruptWaitingRetrieveThreads();
          break;
        }
        if (_threaded) Thread.yield();

        row.setDSDataRow(new DSDataRow(_desc));
      }
      _dataSource.postRetrieve(this);
      _cancelInProgress = false;
      interruptWaitingCancelThreads();
      notifyListeners(ModelChangedEvent.TYPE_DATA_LOADED);
    } catch (Exception e) {
      System.out.println("DataStore.run:" + e);
      _cancelInProgress = false;
      interruptWaitingCancelThreads();
    }

    _retrieveInProgress = false;
    interruptWaitingRetrieveThreads();
    _cancelInProgress = false;
    interruptWaitingCancelThreads();
  }
Пример #2
0
  private synchronized void retrieve(String criteria, boolean countOnly) throws DataStoreException {
    if (!countOnly) reset();
    waitForCancel(); // just in case there was already a retrieve running wait for it to be
                     // cancelled before continuing
    _retrieveInProgress = true;

    try {
      _dataSource.preRetrieve(this, criteria, countOnly);
    } catch (Exception e) {
      try {
        _dataSource.postRetrieve(this);
      } catch (java.sql.SQLException ex) {
        throw new DataStoreException(ex.toString(), ex);
      } catch (Exception ex) {
        throw new DataStoreException(ex.toString());
      }
      _retrieveInProgress = false;
      interruptWaitingRetrieveThreads();
      throw new DataStoreException(e.toString(), e);
    }

    if (!countOnly) {
      if (_threaded) {
        Thread t = new Thread(this);
        t.start();
      } else run();
    }
  }