/* (non-Javadoc)
@see com.googlecode.batchfb.Batcher#paged(java.lang.String, java.lang.Class, com.googlecode.batchfb.Param[])
550490
@Override
	public <T> PagedLater<T> paged(String object, Class<T> type, Param... params) {
		return this.getBatchForGraph().paged(object, type, params);
	}
222802
@Override
    public PaginatedList queryForPaginatedList(String statementName, Object parameterObject,
                                               int pageSize) throws DataAccessException {
        return super.queryForPaginatedList(statementName, parameterObject, pageSize);
    }
121304
public static void printPageList(ChainWriter out, WebSiteRequest req, HttpServletResponse resp, WebPage parent, WebPageLayout layout) throws IOException, SQLException {
		printPageList(out, req, resp, parent.getCachedPages(req), layout);
	}
660768
public Query execute(PageContext pc, SQL sql, Selects selects, int maxrows) throws PageException {
	Column[] orders = selects.getOrderbys();
	Select[] arrSelects = selects.getSelects();

	QueryImpl target = new QueryImpl(new Collection.Key[0], 0, "query", sql);

	for (int i = 0; i < arrSelects.length; i++) {
	    arrSelects[i].getFroms();
	    Column[] froms = arrSelects[i].getFroms();
	    if (froms.length > 1) throw new DatabaseException("can only work with single tables yet", null, sql, null);
	    executeSingle(pc, arrSelects[i], getSingleTable(pc, froms[0]), target, arrSelects.length > 1 ? -1 : maxrows, sql, orders.length > 0);
	}

	// Order By
	if (orders.length > 0) {
	    order(target, orders);
	    if (maxrows > -1) target.cutRowsTo(maxrows);
	}
	// Distinct
	if (selects.isDistinct()) {
	    order(target, selects.getDistincts()); // order to filter
	    // print.e(selects.getDistincts());
	    Key[] _keys = target.getColumnNames();
	    QueryColumn[] columns = new QueryColumn[_keys.length];
	    for (int i = 0; i < columns.length; i++) {
		columns[i] = target.getColumn(_keys[i]);
	    }

	    int i;
	    Object l, r;
	    outer: for (int row = target.getRecordcount(); row > 1; row--) {
		for (i = 0; i < columns.length; i++) {
		    l = columns[i].get(row, null);
		    r = columns[i].get(row - 1, null);
		    if (l == null || r == null) {
			if (l != r) continue outer;
		    }
		    else if (!Operator.equals(l, r, true)) continue outer;
		}
		target.removeRow(row);
	    }
	}
	order(target, orders);

	return target;
    }
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();
    }
427443
protected void writeBatchEntry(StringBuilder sb, ExecutionInfo execInfo, List<QueryInfo> queryInfoList) {
        sb.append("\"batch\":");
        sb.append(execInfo.isBatch() ? "true" : "false");
        sb.append(", ");
    }
697855
private StringBuilder appendPagingSortSQL(final StringBuilder sql, final Post.Sort sort,final Paging paging) {

      if(paging.interval != null) {
         sql.append(" AND post_date");
         sql.append(paging.startIsOpen ? " >" : " >=");
         sql.append("?");

         sql.append(" AND post_date");
         sql.append(paging.endIsOpen ? " <" : " <=");
         sql.append("?");
      }

      switch(sort) {
         case ASC:
            sql.append(" ORDER BY post_date ASC");
            break;
         case DESC:
            sql.append(" ORDER BY post_date DESC");
            break;
         case ASC_MOD:
            sql.append(" ORDER BY post_modified ASC");
            break;
         case DESC_MOD:
            sql.append(" ORDER BY post_modified DESC");
            break;
         case ID_ASC:
            sql.append(" ORDER BY ID ASC");
            break;
         case ID_DESC:
            sql.append(" ORDER BY ID DESC");
            break;
         default:
            sql.append(" ORDER BY post_date DESC");
            break;
      }
      sql.append(" LIMIT ?,?");
      return sql;
   }
1331671
private final void doPrint(String data) {
        // cache data now.
        LogRecord se = cacheTraceData(data);
        if (se != null) {
            dispatchEvent(se);
        }

    }
330156
public final <C extends IRequestablePage> C newPage(final Class<C> pageClass) {
        PageFactory<C> content = getFactory(pageClass);
        if (content != null) {
            return content.createPage(new PageParameters());
        }
        return new DefaultPageFactory().newPage(pageClass);
    }
351770
private <K, C> Iterator<Column<C>> executePaginated(final RowQuery<K, C> query) {
        return Iterators.concat(new AbstractIterator<Iterator<Column<C>>>() {
            @Override
            protected Iterator<Column<C>> computeNext() {
                ColumnList<C> page = execute(query);
                return !page.isEmpty() ? page.iterator() : endOfData();
            }
        });
    }
448199
private static List<ArrayParameter> arrayParametersSortedAsc(Map<String, List<Integer>> parameterNamesToIndexes,
                                                                 Map<String, Query.ParameterSetter> parameters,
                                                                 boolean allowArrayParameters) {
        List<ArrayParameters.ArrayParameter> arrayParameters = new ArrayList<>();
        for(Map.Entry<String, Query.ParameterSetter> parameter : parameters.entrySet()) {
            if (parameter.getValue().parameterCount > 1) {
                if (!allowArrayParameters) {
                    throw new Sql2oException("Array parameters are not allowed in batch mode");
                }
                for(int i : parameterNamesToIndexes.get(parameter.getKey())) {
                    arrayParameters.add(new ArrayParameters.ArrayParameter(i, parameter.getValue().parameterCount));
                }
            }
        }
        Collections.sort(arrayParameters);

        return arrayParameters;
    }
633101
@Override
    public PageException execute(String id) {
	SpoolerTask task = getTaskById(openDirectory, id);
	if (task == null) task = getTaskById(closedDirectory, id);
	if (task != null) {
	    return execute(task);
	}
	return null;
    }
1333290
public static PageRequestDto createPageRequestDto(final PageRequest pageRequest) {
        final PageRequestDto pageRequestDto;
        if (pageRequest == null) {
            pageRequestDto = null;
        } else if (pageRequest instanceof PageRequestDto) {
            pageRequestDto = (PageRequestDto) pageRequest;
        } else {
            pageRequestDto = new PageRequestDto(pageRequest);
        }
        return pageRequestDto;
    }
367061
@Override
  public void addBatch(String sql) throws SQLException {
    checkClosed();

    if (batchStatements == null) {
      batchStatements = new ArrayList<Query>();
      batchParameters = new ArrayList<ParameterList>();
    }

    // Simple statements should not replace ?, ? with $1, $2
    boolean shouldUseParameterized = false;
    CachedQuery cachedQuery = connection.createQuery(sql, replaceProcessingEnabled, shouldUseParameterized);
    batchStatements.add(cachedQuery.query);
    batchParameters.add(null);
  }
501809
@Override
    public String prepareBatchQuery(List<String> statements) {

        StringBuilder sb = new StringBuilder("BEGIN BATCH \n");

        for (String statement : statements) {
            sb.append(statement).append("\n");
        }

        sb.append(" APPLY BATCH;");

        return sb.toString();
    }
191686
public Pageable createPageable() {
        List<Sort.Order> orders = new ArrayList<>();
        for (org.springframework.data.jpa.datatables.mapping.Order order : input.getOrder()) {
            Column column = input.getColumns().get(order.getColumn());
            if (column.getOrderable()) {
                String sortColumn = column.getData();
                Sort.Direction sortDirection = Sort.Direction.fromString(order.getDir());
                orders.add(new Sort.Order(sortDirection, sortColumn));
            }
        }
        Sort sort = orders.isEmpty() ? Sort.unsorted() : Sort.by(orders);

        if (input.getLength() == -1) {
            input.setStart(0);
            input.setLength(Integer.MAX_VALUE);
        }
        return new DataTablesPageRequest(input.getStart(), input.getLength(), sort);
    }
542764
@Override
  public void processEvent(QueryBatch batch) {
    try ( DocumentPage docs = getDocs(batch) ) {
      while ( docs.hasNext() ) {
        for ( Consumer<DocumentRecord> listener : exportListeners ) {
          try {
            listener.accept(docs.next());
          } catch (Throwable t) {
            logger.error("Exception thrown by an onDocumentReady 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);
        }
      }
    }
  }