JDBCPluginsBaseLib.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.core.plugins.dao.jdbc;

  21. import java.sql.Connection;

  22. import org.slf4j.Logger;
  23. import org.openspcoop2.generic_project.dao.jdbc.JDBCServiceManagerProperties;
  24. import org.openspcoop2.generic_project.exception.ExpressionException;
  25. import org.openspcoop2.generic_project.exception.ExpressionNotImplementedException;
  26. import org.openspcoop2.generic_project.exception.MultipleResultException;
  27. import org.openspcoop2.generic_project.exception.NotFoundException;
  28. import org.openspcoop2.generic_project.exception.NotImplementedException;
  29. import org.openspcoop2.generic_project.exception.ServiceException;
  30. import org.openspcoop2.generic_project.expression.IExpression;

  31. import org.openspcoop2.core.plugins.IdPlugin;
  32. import org.openspcoop2.core.plugins.Plugin;
  33. import org.openspcoop2.core.plugins.constants.TipoPlugin;
  34. import org.openspcoop2.core.plugins.dao.IDBPluginServiceSearch;

  35. /**    
  36.  * JDBCPluginsBaseLib
  37.  *
  38.  * @author Poli Andrea (poli@link.it)
  39.  * @author $Author$
  40.  * @version $Rev$, $Date$
  41.  */
  42. public class JDBCPluginsBaseLib {

  43.    
  44.     public static Long getIdPlugin(Connection connection, JDBCServiceManagerProperties jdbcProperties, Logger log,
  45.             TipoPlugin tipoPlugin,String className, boolean throwNotFound) throws ServiceException, NotImplementedException, ExpressionNotImplementedException, ExpressionException, NotFoundException, MultipleResultException{
  46.        
  47.         JDBCServiceManager jdbcServiceManager = new JDBCServiceManager(connection, jdbcProperties, log);
  48.        
  49.         IExpression expressionSearch = jdbcServiceManager.getPluginServiceSearch().newExpression();
  50.         expressionSearch.
  51.             and().
  52.             equals(Plugin.model().TIPO,tipoPlugin).
  53.             equals(Plugin.model().CLASS_NAME,className);
  54.        
  55.         Long id_plugin = null;
  56.         try{
  57.             id_plugin = ((IDBPluginServiceSearch)jdbcServiceManager.getPluginServiceSearch()).findTableId(expressionSearch);
  58.         }catch(NotFoundException notFound){
  59.             if(throwNotFound){
  60.                 throw new NotFoundException(notFound);
  61.             }
  62.         }
  63.        
  64.         return id_plugin;
  65.     }
  66.    
  67.     public static IdPlugin getIdPlugin(Connection connection, JDBCServiceManagerProperties jdbcProperties, Logger log, Long idPlugin) throws ServiceException, NotFoundException, MultipleResultException, NotImplementedException{
  68.        
  69.         JDBCServiceManager jdbcServiceManager = new JDBCServiceManager(connection, jdbcProperties, log);
  70.        
  71.         Plugin p = ((IDBPluginServiceSearch)jdbcServiceManager.getPluginServiceSearch()).get(idPlugin);
  72.        
  73.         return jdbcServiceManager.getPluginServiceSearch().convertToId(p);
  74.        
  75.     }
  76.    
  77.     public static Plugin getPlugin(Connection connection, JDBCServiceManagerProperties jdbcProperties, Logger log, Long idPlugin) throws ServiceException, NotFoundException, MultipleResultException, NotImplementedException{
  78.        
  79.         JDBCServiceManager jdbcServiceManager = new JDBCServiceManager(connection, jdbcProperties, log);
  80.        
  81.         Plugin p = ((IDBPluginServiceSearch)jdbcServiceManager.getPluginServiceSearch()).get(idPlugin);
  82.        
  83.         return p;
  84.        
  85.     }
  86.    
  87.    
  88.    
  89.    
  90.    
  91. }