Beispiel #1
0
  void updateDs(DSDataSourceProxy out) throws DataStoreException, java.sql.SQLException, Exception {
    int rowNo = -1;
    DataStoreRow row = new DataStoreRow(this, null, _desc);

    // do deletes
    for (rowNo = 0; rowNo < _deletedRows.size(); rowNo++) {
      row.setDSDataRow((DSDataRow) _deletedRows.elementAt(rowNo));
      ((DSDataRow) _deletedRows.elementAt(rowNo)).setProxyRow(rowNo);
      if (!out.deleteRow(this, row)) throw new Exception("$Delete$");
    }

    // do the updates
    for (rowNo = 0; rowNo < _rows.size(); rowNo++) {
      row.setDSDataRow((DSDataRow) _rows.elementAt(rowNo));
      ((DSDataRow) _rows.elementAt(rowNo)).setProxyRow(rowNo);
      if (row.getDSDataRow().getRowStatus() == STATUS_MODIFIED) {
        if (!out.updateRow(this, row)) throw new Exception("$Update$");
      }
    }

    // do the inserts
    for (rowNo = 0; rowNo < _rows.size(); rowNo++) {
      row.setDSDataRow((DSDataRow) _rows.elementAt(rowNo));
      ((DSDataRow) _rows.elementAt(rowNo)).setProxyRow(rowNo);
      if (row.getDSDataRow().getRowStatus() == STATUS_NEW_MODIFIED) {
        if (!out.insertRow(this, row)) throw new Exception("$Insert$");
      }
    }
  }
Beispiel #2
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();
  }
Beispiel #3
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();
    }
  }
Beispiel #4
0
 /**
  * Returns a list of column definitions for a particular table in the database that the datastore
  * is using. Note, the datastore must have an app name for this method to work.
  */
 public ColumnDefinition[] getColumnsForTable(String table) {
   try {
     return _dataSource.getColumnsForTable(this, table);
   } catch (Exception ex) {
     return null;
   }
 }
Beispiel #5
0
  /**
   * Updates multiple proxy data stores in a single transaction
   *
   * @param ds The Array of DataStores to update
   * @throws DataStoreException
   */
  public static void update(DataStoreProxy[] ds) throws DataStoreException {

    int i = 0;
    DSDataSourceProxy out = ds[0].getDataSourceProxy();
    try {
      out.preUpdate(ds[0]);
      for (i = 0; i < ds.length; i++) {
        out.writeDSHeader(ds[i]);
        ds[i].setRemoteUpdateReturnValue(null);
        ds[i].updateDs(out);
      }
      out.commit(ds[0]);
      out.postUpdate(ds, true);
      for (i = 0; i < ds.length; i++) ds[i].resetStatus();

    } catch (DataStoreException e) {
      try {
        out.postUpdate(ds, false);
      } catch (Exception ex) {
        System.err.println("DataStoreProxy.update() -- postUpdate:" + ex);
      }
      throw (e);
    } catch (Exception e) {
      try {
        out.postUpdate(ds, false);
      } catch (Exception ex) {
        System.err.println("DataStoreProxy.update() -- postUpdate:" + ex);
      }

      String message = e.getMessage();
      if (message.equals("$Update$") || message.equals("$Insert$") || message.equals("$Delete$")) {
        throw new DataStoreException("DataStore updated canceled.");
      } else throw new DataStoreException(e.toString());
    }
  }
Beispiel #6
0
  /**
   * This method will cause the database to reflect the changes made in the data store's buffer.
   *
   * @exception com.salmonllc.sql.DataStoreException If a SQLError occurs while the datastore is
   *     updating.
   */
  public void update() throws DataStoreException {
    waitForRetrieve();
    DSDataSourceProxy out = _dataSource;
    _updateResults = null;
    DataStoreProxy[] proxy = {this};
    try {
      out.preUpdate(this);
      out.writeDSHeader(this);
      updateDs(out);
      out.commit(this);
      out.postUpdate(proxy, true);
      resetStatus();
      notifyListeners(ModelChangedEvent.TYPE_DATA_LOADED);
    } catch (DataStoreException e) {
      try {
        out.postUpdate(proxy, false);
      } catch (Exception ex) {
        System.err.println("DataStoreProxy.update() -- postUpdate:" + ex);
      }
      throw (e);
    } catch (Exception e) {
      try {
        out.postUpdate(proxy, false);
      } catch (Exception ex) {
        System.err.println("DataStoreProxy.update() -- postUpdate:" + ex);
      }

      String message = e.getMessage();
      if (message.equals("$Update$") || message.equals("$Insert$") || message.equals("$Delete$")) {
        throw new DataStoreException("DataStore updated canceled.");
      } else throw new DataStoreException(e.toString());
    }
  }
Beispiel #7
0
  /**
   * Use this method to get the amount of rows that will be retrieved when a data store retrieve is
   * executed.
   *
   * @param criteria The selection criteria to use for the select.
   */
  public int estimateRowsRetrieved(String criteria) throws DataStoreException {

    try {
      retrieve(criteria, true);
    } catch (DataStoreException e) {
      throw e;
    }
    _retrieveInProgress = false;
    interruptWaitingRetrieveThreads();
    return _dataSource.getCount();
  }
Beispiel #8
0
 /** If a retrieve is in progress, this method will cancel it. */
 public void cancelRetrieve() {
   if (_retrieveInProgress) {
     try {
       _dataSource.cancelRetrieve(this);
     } catch (Exception e) {
       System.out.println("DataStoreProxy.cancelRetrieve" + e);
     }
     _retrieveInProgress = false;
     interruptWaitingRetrieveThreads();
   }
 }
Beispiel #9
0
 /**
  * This method will ping the server for this particular data store. Pinging from time to time will
  * prevent the server session from expiring.
  *
  * @return true if the ping succeeds and false if not.
  */
 public boolean ping() throws Exception {
   return _dataSource.ping(this);
 }
Beispiel #10
0
 /**
  * This method will destroy the remote data store on the data server. All resources on the server
  * will be reclaimed.
  */
 public void destroy() throws Exception {
   _dataSource.destroy(this);
 }