/* (non-Javadoc)
@see com.googlecode.batchfb.Batcher#paged(java.lang.String, java.lang.Class, com.googlecode.batchfb.Param[])
196658
@Override
	public <T> PagedLater<T> paged(String object, Class<T> type, Param... params) {
		if (!object.contains("/"))
			throw new IllegalArgumentException("You can only use paged() for connection requests, eg me/friends");

		// For example if type is User.class, this will produce Paged<User>
		JavaType pagedType = mapper.getTypeFactory().constructParametricType(Paged.class, mapper.getTypeFactory().constructType(type));
			
		GraphRequest<Paged<T>> req = this.graph(object, pagedType, params);
			
		return new PagedLaterAdapter<T>(this.master, req, type);
	}
1112673
@Override
	public int[] doBatch(final SqlContext sqlContext, final PreparedStatement preparedStatement, final int[] result) {
		if (LOG.isDebugEnabled()) {
			int[] counts = result;
			try {
				counts = new int[] { preparedStatement.getUpdateCount() };
			} catch (SQLException ex) {
				ex.printStackTrace();
			}

			StringBuilder builder = new StringBuilder();
			for (int val : counts) {
				builder.append(val).append(", ");
			}
			LOG.debug("SQL:{} executed. Result:{}", sqlContext.getSqlName(), builder.toString());
		}
		return result;
	}
91602
private void doStartBatch(String batchID) {
    if (currentBatch != null && currentBatch.id().equals(batchID)) {
      currentBatch.handleStart();
    }
  }
1086614
public static Object call(PageContext pc, String sql, Object params, Struct options, String name) throws PageException {
	PageContextImpl pci = (PageContextImpl) pc;
	lucee.runtime.tag.Query qry = (lucee.runtime.tag.Query) pci.use(lucee.runtime.tag.Query.class.getName(), "cfquery", TagLibTag.ATTRIBUTE_TYPE_FIXED);

	try {
	    try {
		qry.hasBody(true);
		// set attributes
		qry.setReturnVariable(true);
		qry.setName(StringUtil.isEmpty(name) ? "QueryExecute" : name);
		if (options != null) TagUtil.setAttributeCollection(pc, qry, null, options, TagLibTag.ATTRIBUTE_TYPE_FIXED);
		qry.setParams(params);

		int res = qry.doStartTag();
		pc.initBody(qry, res);
		pc.forceWrite(sql);
		qry.doAfterBody();
	    }
	    catch (Throwable t) {
		ExceptionUtil.rethrowIfNecessary(t);
		try {
		    qry.doCatch(t);
		}
		catch (Throwable t2) {
		    ExceptionUtil.rethrowIfNecessary(t);
		    throw Caster.toPageException(t2);
		}
	    }
	    finally {
		pc.popBody();
		qry.doFinally();
	    }
	    qry.doEndTag();
	    return qry.getReturnVariable();
	}
	finally {
	    pci.reuse(qry);
	}

    }
858187
void doBatchEnd(String batch, Object args) {
    checkOpen();
    JsonObject message = createMessage(args)
        .putString("action", "endBatch")
        .putString("batch", batch);
    if (open && !paused) {
      if (log.isDebugEnabled()) {
        log.debug(String.format("%s - Batch end: Batch[batch=%s, args=%s]", this, batch, args));
      }
      eventBus.send(inAddress, message);
    }
    if (currentBatch != null && currentBatch.id().equals(batch)) {
      currentBatch = null;
    }
  }
100351
@Override
    protected void doHandle(CommandContext ctx) throws CommandFormatException {
        BatchManager batchManager = ctx.getBatchManager();
        if(!batchManager.isBatchActive()) {
            throw new CommandFormatException("No active batch.");
        }
        Batch activeBatch = batchManager.getActiveBatch();
        List<BatchedCommand> commands = activeBatch.getCommands();
        if (!commands.isEmpty()) {
            for (int i = 0; i < commands.size(); ++i) {
                BatchedCommand cmd = commands.get(i);
                ctx.printLine("#" + (i + 1) + ' ' + cmd.getCommand());
            }
        } else {
            ctx.printLine("The batch is empty.");
        }
    }
1374157
protected void getNextPage() {
		    	    	
        final JSONObject params = new JSONObject();
        
        page++;
        
        params.put("page", page);
        params.put("size", size);
        
        clear();
        
        getPage(params);
                
	}
504682
protected Collection invokePage(int pPageIndex, int pPageSize) {
        if(mDao instanceof BaseSelectPageMapper)
        {
            return ((BaseSelectPageMapper)mDao).selectPage(createModel(),pPageIndex,pPageSize);
        }
        else if( mDao instanceof MysqlSelectPageMapper)
        {
            return ((MysqlSelectPageMapper)mDao).selectPage(createModel(),pPageIndex,pPageSize);
        }
        else if(mDao instanceof  Mapper)
        {
            Mapper mapper= (Mapper)mDao;
            return mapper.selectByRowBounds(createModel(),new RowBounds(pPageIndex-1,pPageSize));
        }
        return new ArrayList();
    }
869843
@Override
    public String getPageSql(MappedStatement ms, BoundSql boundSql, Object parameterObject, RowBounds rowBounds, CacheKey pageKey) {
        String sql = boundSql.getSql();
        Page page = this.getLocalPage();
        String orderBy = page.getOrderBy();
        if (StringUtil.isNotEmpty(orderBy)) {
            pageKey.update(orderBy);
            sql = this.replaceSql.replace(sql);
            sql = OrderByParser.converToOrderBySql(sql, orderBy);
            sql = this.replaceSql.restore(sql);
        }

        return page.isOrderByOnly() ? sql : this.getPageSql(sql, page, pageKey);
    }
1159301
@Override
    public final void pagedExecute(String queryId, LogicalWorkflow workflow, IResultHandler resultHandler,
                                   int pageSize) throws ConnectorException {
        Long time = null;
        try {
            for (LogicalStep project : workflow.getInitialSteps()) {
                ClusterName clusterName = ((Project) project).getClusterName();
                connectionHandler.startJob(clusterName.getName());
            }
            if (logger.isDebugEnabled()) {
                logger.debug("Async paged Executing [" + workflow.toString() + "] : queryId [" + queryId + "]");
            }
            time = System.currentTimeMillis();
            pagedExecuteWorkFlow(queryId, workflow, resultHandler, pageSize);

            if (logger.isDebugEnabled()) {
                logger.debug(
                        "The async query [" + queryId + "] has ended");
            }
        } finally {
            for (LogicalStep project : workflow.getInitialSteps()) {
                connectionHandler.endJob(((Project) project).getClusterName().getName());
            }
            if (time != null) {
                logger.info("TIME - The execute time to paged executed with queryId [" + queryId + "] has been [" + (System
                        .currentTimeMillis() - time)
                        + "]");
            }
        }

    }
315614
public static  <E> List<E> pageQuery(Dialect dialect, Executor executor, MappedStatement ms, Object parameter,
                                 RowBounds rowBounds, ResultHandler resultHandler,
                                 BoundSql boundSql, CacheKey cacheKey) throws SQLException {
        //判断是否需要进行分页查询
        if (dialect.beforePage(ms, parameter, rowBounds)) {
            //生成分页的缓存 key
            CacheKey pageKey = cacheKey;
            //处理参数对象
            parameter = dialect.processParameterObject(ms, parameter, boundSql, pageKey);
            //调用方言获取分页 sql
            String pageSql = dialect.getPageSql(ms, boundSql, parameter, rowBounds, pageKey);
            BoundSql pageBoundSql = new BoundSql(ms.getConfiguration(), pageSql, boundSql.getParameterMappings(), parameter);

            Map<String, Object> additionalParameters = getAdditionalParameter(boundSql);
            //设置动态参数
            for (String key : additionalParameters.keySet()) {
                pageBoundSql.setAdditionalParameter(key, additionalParameters.get(key));
            }
            //执行分页查询
            return executor.query(ms, parameter, RowBounds.DEFAULT, resultHandler, pageKey, pageBoundSql);
        } else {
            //不执行分页的情况下，也不执行内存分页
            return executor.query(ms, parameter, RowBounds.DEFAULT, resultHandler, cacheKey, boundSql);
        }
    }
132216
public JSONObject batch(JSONArray actions, RequestOptions requestOptions) throws AlgoliaException {
    return postBatch(actions, requestOptions);
  }
27075
@Override
	public void onEndPage(final PdfWriter writer, final Document document) {
		final int pageN = writer.getPageNumber();
		final String text = pageN + " / ";
		final float len = bf.getWidthPoint(text, 8);
		cb.beginText();
		cb.setFontAndSize(bf, 8);
		final float width = document.getPageSize().getWidth();
		cb.setTextMatrix(width / 2, 30);
		cb.showText(text);
		cb.endText();
		cb.addTemplate(template, width / 2 + len, 30);
	}
439135
public String pageBody(int segment, String className, String parameters) {

        if (segment == HTML_START) {
            StringBuffer result = new StringBuffer(128);
            result.append("</head>\n<body unselectable=\"on\"");
            if (className != null) {
                result.append(" class=\"");
                result.append(className);
                result.append("\"");
            }
            if (CmsStringUtil.isNotEmpty(parameters)) {
                result.append(" ");
                result.append(parameters);
            }
            result.append(">\n");
            return result.toString();
        } else {
            return "</body>";
        }
    }
592633
public void setParam(String type, String file, String fileName, String name, String value, String disposition, String contentID, Boolean oRemoveAfterSend)
	    throws PageException {
	if (file != null) {
	    boolean removeAfterSend = (oRemoveAfterSend == null) ? remove : oRemoveAfterSend.booleanValue();

	    setMimeattach(file, fileName, type, disposition, contentID, removeAfterSend);
	}
	else {
	    if (name.equalsIgnoreCase("bcc")) setBcc(value);
	    else if (name.equalsIgnoreCase("cc")) setCc(value);
	    else if (name.equalsIgnoreCase("charset")) setCharset(CharsetUtil.toCharset(value, null));
	    else if (name.equalsIgnoreCase("failto")) setFailto(value);
	    else if (name.equalsIgnoreCase("from")) setFrom(value);
	    else if (name.equalsIgnoreCase("mailerid")) setMailerid(value);
	    else if (name.equalsIgnoreCase("mimeattach")) setMimeattach(value);
	    else if (name.equalsIgnoreCase("priority")) setPriority(value);
	    else if (name.equalsIgnoreCase("replyto")) setReplyto(value);
	    else if (name.equalsIgnoreCase("subject")) setSubject(value);
	    else if (name.equalsIgnoreCase("to")) setTo(value);

	    else smtp.addHeader(name, value);
	}
    }
787803
public static <E> Page<E> startPage(int pageNum, int pageSize, String orderBy) {
        Page<E> page = startPage(pageNum, pageSize);
        page.setOrderBy(orderBy);
        return page;
    }
786188
public void processEvent(QueryBatch batch) {
    if ( ! (batch.getClient() instanceof DatabaseClientImpl) ) {
      throw new IllegalStateException("DatabaseClient must be instanceof DatabaseClientImpl");
    }
    StringHandle uris = new StringHandle(String.join("\n", batch.getItems()))
      .withMimetype("text/uri-list");
    RESTServices services = ((DatabaseClientImpl) batch.getClient()).getServices();
    try {
      RequestParameters params = new RequestParameters();
      if ( transform != null ) transform.merge(params);
      params.add("result", applyResult.toString().toLowerCase());
      List<String> responseUris = new BufferedReader(
        services.postResource(null, "internal/apply-transform", null, params, uris, new ReaderHandle()).get()
      ).lines().collect(Collectors.toList());
      QueryBatchImpl processedBatch = new QueryBatchImpl()
        .withClient( batch.getClient() )
        .withItems( responseUris.toArray(new String[responseUris.size()]) )
        .withTimestamp( batch.getTimestamp() )
        .withJobBatchNumber( batch.getJobBatchNumber() )
        .withJobResultsSoFar( batch.getJobResultsSoFar() )
        .withForestBatchNumber( batch.getForestBatchNumber() )
        .withForestResultsSoFar( batch.getForestResultsSoFar() )
        .withForest( batch.getForest() )
        .withServerTimestamp( batch.getServerTimestamp() )
        .withJobTicket( batch.getJobTicket() );
      for ( QueryBatchListener listener : successListeners ) {
        try {
          listener.processEvent(processedBatch);
        } catch (Throwable t) {
          logger.error("Exception thrown by an onSuccess listener", t);
        }
      }

      List<String> skippedRequestUris = new ArrayList<>(Arrays.asList(batch.getItems()));
      skippedRequestUris.removeAll( responseUris );
      if ( skippedRequestUris.size() > 0 ) {
        QueryBatchImpl skippedBatch = processedBatch
          .withItems( skippedRequestUris.toArray(new String[0]) );
        for ( QueryBatchListener listener : skippedListeners ) {
          try {
            listener.processEvent(skippedBatch);
          } catch (Throwable t) {
            logger.error("Exception thrown by an onSkipped listener", t);
          }
        }
      }
    } catch (Throwable t) {
      for ( BatchFailureListener<Batch<String>> listener : failureListeners ) {
        try {
          listener.processFailure(batch, t);
        } catch (Throwable t2) {
          logger.error("Exception thrown by an onBatchFailure listener", t2);
        }
      }
      for ( BatchFailureListener<QueryBatch> queryBatchFailureListener : queryBatchFailureListeners ) {
        try {
          queryBatchFailureListener.processFailure(batch, t);
        } catch (Throwable t2) {
          logger.error("Exception thrown by an onFailure listener", t2);
        }
      }
      logger.warn("Error: {} in batch with urs ({})", t.toString(),
        Arrays.asList(batch.getItems()));
    }
  }