PaginatedExpressionImpl.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */
  20. package org.openspcoop2.generic_project.expression.impl;

  21. import org.openspcoop2.generic_project.exception.ExpressionException;
  22. import org.openspcoop2.generic_project.exception.ExpressionNotImplementedException;
  23. import org.openspcoop2.generic_project.expression.IPaginatedExpression;
  24. import org.openspcoop2.generic_project.expression.impl.formatter.IObjectFormatter;


  25. /**
  26.  * PaginatedExpressionImpl
  27.  *
  28.  * @author Poli Andrea (apoli@link.it)
  29.  * @author $Author$
  30.  * @version $Rev$, $Date$
  31.  */
  32. public class PaginatedExpressionImpl extends ExpressionImpl implements IPaginatedExpression {

  33.     public PaginatedExpressionImpl() throws ExpressionException {
  34.         super();
  35.     }
  36.     public PaginatedExpressionImpl(IObjectFormatter objectFormatter) throws ExpressionException{
  37.         super(objectFormatter);
  38.     }
  39.     public PaginatedExpressionImpl(ExpressionImpl expr) throws ExpressionException{
  40.         super(expr);
  41.     }
  42.    
  43.     private Integer limit = null;
  44.     private Integer offset = null;
  45.    
  46.     /**
  47.      * Sets the maximum number of results
  48.      *
  49.      * @param limit maximum number of results
  50.      * @return the instance of itself
  51.      * @throws ExpressionNotImplementedException Method not implemented
  52.      * @throws ExpressionException Error Processing
  53.      */
  54.     @Override
  55.     public IPaginatedExpression limit(int limit) throws ExpressionNotImplementedException,
  56.             ExpressionException {
  57.         this.limit = limit;
  58.         return this;
  59.     }

  60.     /**
  61.      * Set the offset from which to search
  62.      *
  63.      * @param offset offset
  64.      * @return the instance of itself
  65.      * @throws ExpressionNotImplementedException Method not implemented
  66.      * @throws ExpressionException Error Processing
  67.      */
  68.     @Override
  69.     public IPaginatedExpression offset(int offset) throws ExpressionNotImplementedException,
  70.             ExpressionException {
  71.         this.offset = offset;
  72.         return this;
  73.     }

  74.     public Integer getLimit() {
  75.         return this.limit;
  76.     }

  77.     public Integer getOffset() {
  78.         return this.offset;
  79.     }



  80.    
  81.     /* ToString */
  82.     @Override
  83.     public String toString(){
  84.         String s = super.toString(false);
  85.         if(s==null){
  86.             return s;
  87.         }
  88.         else{
  89.             StringBuilder bf = new StringBuilder();
  90.             bf.append(s);
  91.            
  92.             if(this.limit!=null && this.limit>=0){
  93.                 bf.append(" LIMIT "+this.limit);
  94.             }
  95.            
  96.             if(this.offset!=null && this.offset>=0){
  97.                 bf.append(" OFFSET "+this.offset);
  98.             }
  99.            
  100.             this.printForceIndex(bf);
  101.            
  102.             return bf.toString();
  103.         }
  104.     }
  105. }