TipiDatabase.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;


  21. /**
  22.  * Contiene i tipi di Database supportati
  23.  *
  24.  * @author Poli Andrea (apoli@link.it)
  25.  * @author $Author$
  26.  * @version $Rev$, $Date$
  27.  */


  28. public enum TipiDatabase {

  29.     POSTGRESQL ("postgresql"),
  30.     MYSQL ("mysql"),
  31.     ORACLE ("oracle"),
  32.     HSQL ("hsql"),
  33.     DERBY ("derby"),
  34.     SQLSERVER ("sqlserver"),
  35.     DB2 ("db2"),
  36.     DEFAULT ("default");
  37.    
  38.    
  39.     private final String nome;

  40.     TipiDatabase(String nome)
  41.     {
  42.         this.nome = nome;
  43.        
  44.     }

  45.     public String getNome()
  46.     {
  47.         return this.nome;
  48.     }
  49.    
  50.     @Override
  51.     public String toString(){
  52.         return this.nome;
  53.     }

  54.    
  55.     public static String[] toStringArray(){
  56.         String[] res = new String[TipiDatabase.values().length];
  57.         int i=0;
  58.         for (TipiDatabase tmp : TipiDatabase.values()) {
  59.             res[i]=tmp.toString();
  60.             i++;
  61.         }
  62.         return res;
  63.     }
  64.    
  65.     public static String[] toEnumNameArray(){
  66.         String[] res = new String[TipiDatabase.values().length];
  67.         int i=0;
  68.         for (TipiDatabase tmp : TipiDatabase.values()) {
  69.             res[i]=tmp.name();
  70.             i++;
  71.         }
  72.         return res;
  73.     }
  74.    
  75.     public static TipiDatabase toEnumConstant(String val){
  76.        
  77.         if(TipiDatabase.POSTGRESQL.toString().equals(val)){
  78.             return TipiDatabase.POSTGRESQL;
  79.         }else if(TipiDatabase.MYSQL.toString().equals(val)){
  80.             return TipiDatabase.MYSQL;
  81.         }else if(TipiDatabase.ORACLE.toString().equals(val)){
  82.             return TipiDatabase.ORACLE;
  83.         }else if(TipiDatabase.HSQL.toString().equals(val)){
  84.             return TipiDatabase.HSQL;
  85.         }else if(TipiDatabase.DERBY.toString().equals(val)){
  86.             return TipiDatabase.DERBY;
  87.         }else if(TipiDatabase.SQLSERVER.toString().equals(val)){
  88.             return TipiDatabase.SQLSERVER;
  89.         }else if(TipiDatabase.DB2.toString().equals(val)){
  90.             return TipiDatabase.DB2;
  91.         }else{
  92.             return TipiDatabase.DEFAULT;
  93.         }
  94.        
  95.     }
  96.    
  97.    
  98.     public static boolean isAMember(String tipoDatabase){      
  99.         for (TipiDatabase val : TipiDatabase.values()){        
  100.             if (val.equals(tipoDatabase))
  101.                 return true;
  102.         }
  103.         return false;
  104.     }
  105.    
  106.     public boolean equals(String tipoDatabase){
  107.         return this.toString().equalsIgnoreCase(tipoDatabase);
  108.     }
  109. }