SQLObjectFactory.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 org.openspcoop2.utils.TipiDatabase;


  22. /**
  23.  * Factory degli oggetti SQLQueryObject
  24.  *
  25.  *
  26.  * @author Poli Andrea (apoli@link.it)
  27.  * @author $Author$
  28.  * @version $Rev$, $Date$
  29.  */

  30. public class SQLObjectFactory {
  31.    
  32.     private SQLObjectFactory() {}

  33.     public static ISQLQueryObject createSQLQueryObject(String tipoDatabase) throws SQLQueryObjectException {
  34.         return SQLObjectFactory.toQueryObject(tipoDatabase);
  35.     }

  36.     public static ISQLQueryObject createSQLQueryObject(TipiDatabase tipoDatabase) throws SQLQueryObjectException {
  37.         return SQLObjectFactory.createSQLQueryObject(tipoDatabase.toString());
  38.     }
  39.    
  40.     public static ISQLQueryObject toQueryObject(String tipoDatabase) throws SQLQueryObjectException{
  41.         if (TipiDatabase.POSTGRESQL.equals(tipoDatabase)) {
  42.             return new PostgreSQLQueryObject(TipiDatabase.POSTGRESQL);
  43.         } else if (TipiDatabase.MYSQL.equals(tipoDatabase)) {
  44.             return new MySQLQueryObject(TipiDatabase.MYSQL);
  45.         } else if (TipiDatabase.ORACLE.equals(tipoDatabase)) {
  46.             return new OracleQueryObject(TipiDatabase.ORACLE);
  47.         } else if(TipiDatabase.HSQL.toString().equals(tipoDatabase)){
  48.             return new HyperSQLQueryObject(TipiDatabase.HSQL);
  49.         } else if(TipiDatabase.DERBY.toString().equals(tipoDatabase)){
  50.             return new DerbyQueryObject(TipiDatabase.DERBY);
  51.         } else if(TipiDatabase.SQLSERVER.toString().equals(tipoDatabase)){
  52.             return new SQLServerQueryObject(TipiDatabase.SQLSERVER);            
  53.         } else if(TipiDatabase.DB2.toString().equals(tipoDatabase)){
  54.             return new DB2QueryObject(TipiDatabase.DB2);            
  55.         } else {
  56.             throw new SQLQueryObjectException("Tipo database non gestito ["+tipoDatabase+"]");
  57.         }

  58.     }
  59. }