Exemplo n.º 1
0
  public void run() {
    while (!requestShutdown) {
      try {
        logger.debug(Messages.getString("queryScheduler.running"));
        synchronized (this) {
          while (queue.size() != 0) executeNextInQueue();

          logger.debug(Messages.getString("queryScheduler.waitingForMore"));
          wait();
        }
      } catch (Exception e) {
        logger.error(e);
        e.printStackTrace();
      }
    }
  }
Exemplo n.º 2
0
 public ResultSet executeQuery(AbstractQueryManager s) throws RemoteException, SQLException {
   // Isto e thread-safe?
   put(s);
   ResultSet rs = null;
   try {
     rs = ((SelectQueryManager) s).executeQuery();
     logger.debug(Messages.getString("queryScheduler.queryExecuted", s.getQueryNumber()));
   } catch (SQLException e) {
     logger.error(
         Messages.getString(
             "queryScheduler.queryError", new Object[] {s.getQueryNumber(), e.getMessage()}));
     remove(s);
     throw e;
   }
   remove(s);
   return rs;
 }
Exemplo n.º 3
0
 public int executeUpdate(AbstractQueryManager s) throws RemoteException, SQLException {
   // Isto e thread-safe?
   put(s);
   int count = -1;
   try {
     count = ((UpdateQueryManager) s).executeUpdate();
     logger.debug(Messages.getString("queryScheduler.queryExecuted", s.getQueryNumber()));
   } catch (SQLException e) {
     logger.error(
         Messages.getString(
             "queryScheduler.queryError", new Object[] {s.getQueryNumber(), e.getMessage()}));
     remove(s);
     throw e;
   }
   remove(s);
   return count;
 }
Exemplo n.º 4
0
  public synchronized void remove(AbstractQueryManager s) {
    executingQueries.remove(s);
    if (s.getClass().equals(UpdateQueryManager.class)) {
      connectionManager.invalidMetaData();
      executingUpdate.set(false);
    }
    logger.debug(Messages.getString("queryScheduler.remove", s.getQueryNumber()));

    notifyAll();
  }
Exemplo n.º 5
0
  public void put(AbstractQueryManager s) {
    s.setScheduller(this);

    longTransactionQueue.wait(s);
    synchronized (this) {
      queue.add(s);
      logger.debug(Messages.getString("queryScheduler.added", s.getQueryNumber()));
      notifyAll();
    }
  }
Exemplo n.º 6
0
  private void executeNextInQueue() throws Exception {
    AbstractQueryManager s;

    // Update isolation
    while (executingUpdate.get()) {
      logger.debug(Messages.getString("queryScheduler.waitingForUpdateEnd"));
      wait();
    }
    while ((((AbstractQueryManager) queue.peek()).getClass().equals(UpdateQueryManager.class))
        && (pendingQueries() > 0)) {
      logger.debug(Messages.getString("queryScheduler.waitingForPending"));
      wait();
    }
    s = (AbstractQueryManager) queue.poll();
    executingQueries.add(s);
    if (s.getClass().equals(UpdateQueryManager.class)) executingUpdate.set(true);

    logger.debug(Messages.getString("queryScheduler.dispatching", s.getQueryNumber()));
    s.go();
  }