/*
Start the historics query given

@return a result which can be checked for success or failure, A status 204 indicates success,
or using {@link com.datasift.client.BaseDataSiftResult#isSuccessful()}
501914
public FutureData<DataSiftResult> start(FutureData<PreparedHistoricsQuery> query) {
        if (query == null) {
            throw new IllegalArgumentException("A valid PreparedHistoricsQuery is required");
        }
        final FutureData<DataSiftResult> future = new FutureData<>();
        DataSiftResult h = new BaseDataSiftResult();

        FutureResponse<PreparedHistoricsQuery> r = new FutureResponse<PreparedHistoricsQuery>() {
            public void apply(PreparedHistoricsQuery data) {
                if (data.getId() == null || data.getId().isEmpty()) {
                    throw new IllegalArgumentException("A valid PreparedHistoricsQuery is required");
                }
                start(data.getId(), future);
            }
        };
        unwrapFuture(query, future, h, r);
        return future;
    }
1031124
public java.util.List<HistoryRecordEntry> getHistoryRecords() {
        if (historyRecords == null) {
            historyRecords = new com.amazonaws.internal.SdkInternalList<HistoryRecordEntry>();
        }
        return historyRecords;
    }
894347
public Query query(DataRange dataRange) {
        RowPosition startPosition = dataRange.startKey();
        RowPosition stopPosition = dataRange.stopKey();
        Token startToken = startPosition.getToken();
        Token stopToken = stopPosition.getToken();
        boolean isSameToken = startToken.compareTo(stopToken) == 0 && !tokenMapper.isMinimum(startToken);
        BooleanClause.Occur occur = isSameToken ? MUST : SHOULD;
        boolean includeStart = tokenMapper.includeStart(startPosition);
        boolean includeStop = tokenMapper.includeStop(stopPosition);

        SliceQueryFilter sqf;
        if (startPosition instanceof DecoratedKey) {
            sqf = (SliceQueryFilter) dataRange.columnFilter(((DecoratedKey) startPosition).getKey());
        } else {
            sqf = (SliceQueryFilter) dataRange.columnFilter(ByteBufferUtil.EMPTY_BYTE_BUFFER);
        }
        Composite startName = sqf.start();
        Composite stopName = sqf.finish();

        BooleanQuery query = new BooleanQuery();

        if (!startName.isEmpty()) {
            BooleanQuery q = new BooleanQuery();
            q.add(tokenMapper.query(startToken), MUST);
            q.add(clusteringKeyMapper.query(startName, null), MUST);
            query.add(q, occur);
            includeStart = false;
        }

        if (!stopName.isEmpty()) {
            BooleanQuery q = new BooleanQuery();
            q.add(tokenMapper.query(stopToken), MUST);
            q.add(clusteringKeyMapper.query(null, stopName), MUST);
            query.add(q, occur);
            includeStop = false;
        }

        if (!isSameToken) {
            Query rangeQuery = tokenMapper.query(startToken, stopToken, includeStart, includeStop);
            if (rangeQuery != null) query.add(rangeQuery, SHOULD);
        } else if (query.getClauses().length == 0) {
            return tokenMapper.query(startToken);
        }

        return query.getClauses().length == 0 ? null : query;
    }
964664
private static GeocodeApiResponse.Result firstResult(final GeocodeApiResponse apiResponse) {
        if (apiResponse.getStatus() != GeocodeApiResponse.Status.OK) {
            return null;
        }
        final List<GeocodeApiResponse.Result> results = apiResponse.getResults();
        if (results.isEmpty()) {
            return null;
        }
        return results.get(0);
    }
968633
public Object initResult()
  {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.entry(tc, "initResult");

    //theResults = new ArrayList();
    Object theResults = new TopicAclTraversalResults();
    
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.exit(tc, "initResult");
    return theResults;
  }
771674
@Override
  public PollResult startPoll(PollController conn)
  {
    if (! _lifecycle.isActive()) {
      log.warning(this + " select disabled");
        
      return PollResult.CLOSED;
    }
    else if (_selectMax <= _connectionCount.get()) {
      log.warning(this + " keepalive overflow "
                  + _connectionCount + " max=" + _selectMax);
      System.out.println("OVERFLOW:");
      
      return PollResult.CLOSED;
    }
    
    if (! conn.toKeepaliveStart()) {
      return PollResult.CLOSED;
    }

    // XXX: check for full
    _executor.execute(new PollTask(conn));
    
    return PollResult.START;
  }
698454
public CountQueryResult executeCount() {
		CountQueryResult ret = new CountQueryResult(this);
		Object so = this.queryExecutor.getMappingInfo().getInternalDomainAccess().getSyncObject();
		if (so != null) {
			synchronized (so) {
				this.queryExecutor.executeCount();
			}
		} else
			this.queryExecutor.executeCount();
		return ret;
	}
925886
public boolean startConnection()
  {
    State state = _state.get();
    
    if (state.isActive()) {
      // when active, always start a connection
      
      _connectionCount.incrementAndGet();
      
      return true;
    }
    
    long now = CurrentTime.currentTime();
    long lastFailTime = _lastFailTime;
    long recoverTimeout = _dynamicRecoverTimeout.get();
    
    if (now < lastFailTime + recoverTimeout) {
      // if the fail recover hasn't timed out, return false
      return false;
    }
    
    // when fail, only start a single connection
    int count;

    do {
      count = _connectionCount.get();
      
      if (count > 0) {
        return false;
      }
    } while (! _connectionCount.compareAndSet(count, count + 1));
    
    return true;
  }
1229303
public QueryResult execute() throws RepositoryException
   {
      checkInitialized();
      long time = 0;
      if (log.isDebugEnabled())
      {
         time = System.currentTimeMillis();
      }

      QueryResult result = query.execute(offset, limit, caseInsensitiveOrder);

      if (log.isDebugEnabled())
      {
         time = System.currentTimeMillis() - time;
         NumberFormat format = NumberFormat.getNumberInstance();
         format.setMinimumFractionDigits(2);
         format.setMaximumFractionDigits(2);
         String seconds = format.format((double)time / 1000);
         log.debug("executed in " + seconds + " s. (" + statement + ")");
      }
      return result;
   }
694467
public boolean execute(final String query) throws SQLException {
        startTimer();
        try {
            if (queryResult != null) {
                queryResult.close();
            }
            queryResult = protocol.executeQuery(queryFactory.createQuery(query));
            if (queryResult.getResultSetType() == ResultSetType.SELECT) {
                setResultSet(new DrizzleResultSet(queryResult, this, getProtocol()));
                return true;
            }
            setUpdateCount(((ModifyQueryResult) queryResult).getUpdateCount());
            return false;
        } catch (QueryException e) {
            throw SQLExceptionMapper.get(e);
        } finally {
            stopTimer();
        }
    }
1343664
public ActivityRecords history(String streamKey, long start, long end) throws QiniuException {
        if (start <= 0 || end < 0 || (start >= end && end != 0)) {
            throw new QiniuException(new IllegalArgumentException("bad argument" + start + "," + end));
        }
        String path = encodeKey(streamKey) + "/historyactivity?start=" + start;
        if (end != 0) {
            path += "&end=" + end;
        }
        return get(path, ActivityRecords.class);
    }
409734
public ReturnCode status(boolean starting) {
        // Use initialized bootstrap configuration to find the server lock file.
        ServerLock serverLock = ServerLock.createTestLock(bootProps);
        ReturnCode rc = ReturnCode.OK;

        // The lock file may have been (erroneously) deleted: this can happen on linux
        boolean lockExists = serverLock.lockFileExists();

        if (lockExists) {
            // If the lock exists, check quickly to see if the process is holding it.
            if (serverLock.testServerRunning()) {
                rc = ReturnCode.OK;
            } else {
                // nope: lock not held, we're not running
                rc = ReturnCode.REDUNDANT_ACTION_STATUS;
            }
        } else {
            // no lock file: we assume the server is not running.
            rc = ReturnCode.REDUNDANT_ACTION_STATUS;
        }

        if (rc == ReturnCode.OK) {
            String pid = getPID();
            if (pid == null) {
                if (starting) {
                    System.out.println(MessageFormat.format(BootstrapConstants.messages.getString("info.serverIsAlreadyRunning"), serverName));
                } else {
                    System.out.println(MessageFormat.format(BootstrapConstants.messages.getString("info.serverIsRunning"), serverName));
                }
            } else {
                if (starting) {
                    System.out.println(MessageFormat.format(BootstrapConstants.messages.getString("info.serverIsAlreadyRunningWithPID"), serverName, pid));
                } else {
                    System.out.println(MessageFormat.format(BootstrapConstants.messages.getString("info.serverIsRunningWithPID"), serverName, pid));
                }
            }
        } else if (rc == ReturnCode.REDUNDANT_ACTION_STATUS) {
            if (!starting) {
                System.out.println(MessageFormat.format(BootstrapConstants.messages.getString("info.serverNotRunning"), serverName));
            }
        } else if (rc == ReturnCode.SERVER_NOT_EXIST_STATUS) {
            System.out.println(MessageFormat.format(BootstrapConstants.messages.getString("info.serverNotExist"), serverName));
        } else {
            if (!starting) {
                System.out.println(MessageFormat.format(BootstrapConstants.messages.getString("info.serverStatusException"), serverName));
            } else {
                if (rc == ReturnCode.SERVER_UNKNOWN_STATUS) {
                    String pid = getPID();
                    String pidFile = launchArgs.getOption(INTERNAL_PID_FILE);
                    if (pid == null || pidFile == null) {
                        System.out.println(MessageFormat.format(BootstrapConstants.messages.getString("info.serverStartException"), serverName));
                    } else {
                        System.out.println(MessageFormat.format(BootstrapConstants.messages.getString("info.serverStartUnreachable"), serverName, pidFile, pid));
                    }
                } else {
                    System.out.println(MessageFormat.format(BootstrapConstants.messages.getString("info.serverStartException"), serverName));
                }
            }
        }

        return rc;
    }
269214
public final SingleCallStatsToken beginProcedure() {
        long invocations = fuzzyInvocationCounter.getAndIncrement();

        boolean samplingProcedure = (invocations % m_procSamplingInterval == 0) || m_isUAC;
        boolean samplingStmts = invocations % m_stmtSamplingInterval == 0;

        long startTimeNanos = samplingProcedure ? System.nanoTime() : 0;

        return new SingleCallStatsToken(startTimeNanos, samplingStmts);
    }
817391
public synchronized boolean hasNext()
    {
        try
        {
            if (!isHasCalledCheck())
            {
                setHasCalledCheck(true);
                setHasNext(getRsAndStmt().m_rs.next());
                if (!getHasNext())
                {
                    autoReleaseDbResources();
                }
            }
        }
        catch (Exception ex)
        {
            setHasNext(false);
            autoReleaseDbResources();
            if(ex instanceof ResourceClosedException)
            {
                throw (ResourceClosedException)ex;
            }
            if(ex instanceof SQLException)
            {
                throw new PersistenceBrokerSQLException("Calling ResultSet.next() failed", (SQLException) ex);
            }
            else
            {
               throw new PersistenceBrokerException("Can't get next row from ResultSet", ex);
            }
        }
        if (logger.isDebugEnabled())
            logger.debug("hasNext() -> " + getHasNext());

        return getHasNext();
    }
698118
@GET
    @Path("{id}/history/{start: " + DATE_REGEX + "}-{end: " + DATE_REGEX + "}")
    public Response fetchHistory(@PathParam("id") URI_ID id,
                                 @PathParam("start") Timestamp start,
                                 @PathParam("end") Timestamp end) throws Exception {
        return super.fetchHistory(id, start, end);
    }
531917
public Status getStatus() {
        String status = m_resultFields.get(STATUS);
        if (status == null) {
            return Status.OK;
        } else {
            return Status.valueOf(status.toUpperCase());
        }
    }
55386
public Scan getResultScan(String tableName, String famName,
             ByteBuffer startKey, ByteBuffer endKey) throws IOException {
	 logger.debug("AbstractHBaseUtils Begin of getResultScan(" + tableName + ", " + famName + ")");
         Scan scan = new Scan();
         scan.addFamily(Bytes.toBytes(famName));
         // For a range scan, set start / stop id or just start.
         if (startKey != null)
             scan.setStartRow(Bytes.toBytes(startKey));
         if (endKey != null)
             scan.setStopRow(Bytes.toBytes(endKey));
         return scan;
     }