Comparator.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.expression.impl.sql.ISQLFieldConverter;
  22. import org.openspcoop2.utils.LoggerWrapperFactory;
  23. import org.openspcoop2.utils.TipiDatabase;

  24. /**
  25.  * Comparator
  26.  *
  27.  * @author Poli Andrea (apoli@link.it)
  28.  * @author $Author$
  29.  * @version $Rev$, $Date$
  30.  */
  31. public enum Comparator {

  32.     EQUALS("="),NOT_EQUALS("<>"),
  33.     GREATER_THAN(">"),GREATER_EQUALS(">="),
  34.     LESS_THAN("<"),LESS_EQUALS("<="),
  35.     IS_NULL("is null"),IS_NOT_NULL("is not null"),
  36.     IS_EMPTY("= ''"),IS_NOT_EMPTY("<> ''");
  37.    
  38.     private String operatore = null;
  39.    
  40.     Comparator(String value){
  41.         this.operatore = value;
  42.     }
  43.    
  44.     public String getOperatore() {
  45.         return this.getOperatore(null);
  46.     }
  47.     public String getOperatore(ISQLFieldConverter sqlFieldConverter) {
  48.         try {
  49.             if(sqlFieldConverter!=null && sqlFieldConverter.getDatabaseType()!=null &&
  50.                 (TipiDatabase.ORACLE.equals(sqlFieldConverter.getDatabaseType()))
  51.                 ){
  52.                 if(IS_EMPTY.equals(this)) {
  53.                     return IS_NULL.getOperatore();
  54.                 }
  55.                 else if(IS_NOT_EMPTY.equals(this)) {
  56.                     return IS_NOT_NULL.getOperatore();
  57.                 }
  58.             }
  59.         }catch(Exception e) {
  60.             LoggerWrapperFactory.getLogger(Comparator.class).error(e.getMessage(),e);
  61.         }
  62.         return this.operatore;
  63.     }
  64. }