Case.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.utils.sql;

  21. import java.util.ArrayList;
  22. import java.util.List;

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

  31.     private List<String> condizioni = new ArrayList<>();
  32.     private List<String> valori = new ArrayList<>();
  33.     private CastColumnType tipoColonna;
  34.     private int dimensioneColonna = 255;
  35.     private String valoreDefault;

  36.     private boolean stringValueType = false;

  37.     public Case(CastColumnType type) throws SQLQueryObjectException {
  38.         this.stringValueType = false;
  39.         this.tipoColonna = type;
  40.         if(this.tipoColonna==null) {
  41.             throw new SQLQueryObjectException("Tipo Colonna non fornito");
  42.         }
  43.     }
  44.     public Case(CastColumnType type, String valoreDefault) throws SQLQueryObjectException {
  45.         this(type, false, valoreDefault);
  46.     }
  47.     public Case(CastColumnType type, boolean stringValueType, String valoreDefault) throws SQLQueryObjectException{
  48.         this.stringValueType = stringValueType;
  49.         if(valoreDefault==null) {
  50.             throw new SQLQueryObjectException("Valore di default non fornito");
  51.         }
  52.         this.valoreDefault = valoreDefault;
  53.        
  54.         this.tipoColonna = type;
  55.         if(this.tipoColonna==null) {
  56.             throw new SQLQueryObjectException("Tipo Colonna non fornito");
  57.         }
  58.     }
  59.    
  60.     public void addCase(String condizione, String valore) throws SQLQueryObjectException {
  61.         this.condizioni.add(condizione);
  62.         this.valori.add(valore);
  63.        
  64.         if(condizione==null) {
  65.             throw new SQLQueryObjectException("Condizione non fornita");
  66.         }
  67.         if(valore==null) {
  68.             throw new SQLQueryObjectException("Valore non fornito");
  69.         }
  70.     }

  71.     public List<String> getCondizioni() {
  72.         return this.condizioni;
  73.     }

  74.     public List<String> getValori() {
  75.         return this.valori;
  76.     }
  77.    
  78.     public boolean isStringValueType() {
  79.         return this.stringValueType;
  80.     }

  81.     public void setStringValueType(boolean stringValueType) {
  82.         this.stringValueType = stringValueType;
  83.     }
  84.    
  85.     public String getValoreDefault() {
  86.         return this.valoreDefault;
  87.     }
  88.    
  89.     public CastColumnType getTipoColonna() {
  90.         return this.tipoColonna;
  91.     }

  92.     public int getDimensioneColonna() {
  93.         return this.dimensioneColonna;
  94.     }
  95.     public void setDimensioneColonna(int dimensioneColonna) {
  96.         this.dimensioneColonna = dimensioneColonna;
  97.     }
  98. }