JDBCStatisticaInfoServiceSearch.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.statistiche.dao.jdbc;

  21. import org.openspcoop2.generic_project.dao.IDBServiceUtilities;
  22. import org.openspcoop2.generic_project.dao.jdbc.IJDBCServiceSearchWithoutId;
  23. import org.openspcoop2.generic_project.beans.IField;
  24. import org.openspcoop2.generic_project.beans.NonNegativeNumber;
  25. import org.openspcoop2.generic_project.beans.UnionExpression;
  26. import org.openspcoop2.generic_project.beans.Union;
  27. import org.openspcoop2.generic_project.beans.FunctionField;
  28. import org.openspcoop2.generic_project.dao.jdbc.JDBCServiceManagerProperties;
  29. import org.openspcoop2.generic_project.exception.ExpressionException;
  30. import org.openspcoop2.generic_project.exception.MultipleResultException;
  31. import org.openspcoop2.generic_project.exception.NotFoundException;
  32. import org.openspcoop2.generic_project.exception.NotImplementedException;
  33. import org.openspcoop2.generic_project.exception.ServiceException;
  34. import org.openspcoop2.generic_project.exception.ValidationException;
  35. import org.openspcoop2.generic_project.expression.IExpression;
  36. import org.openspcoop2.generic_project.expression.IPaginatedExpression;
  37. import org.openspcoop2.generic_project.expression.impl.sql.ISQLFieldConverter;
  38. import org.openspcoop2.generic_project.dao.jdbc.JDBCExpression;
  39. import org.openspcoop2.generic_project.dao.jdbc.JDBCPaginatedExpression;
  40. import org.openspcoop2.generic_project.dao.jdbc.JDBCProperties;
  41. import org.openspcoop2.generic_project.dao.jdbc.utils.IJDBCFetch;
  42. import org.openspcoop2.generic_project.dao.jdbc.utils.JDBC_SQLObjectFactory;

  43. import org.openspcoop2.core.statistiche.StatisticaInfo;
  44. import org.openspcoop2.core.statistiche.dao.IStatisticaInfoServiceSearch;
  45. import org.openspcoop2.core.statistiche.utils.ProjectInfo;

  46. import java.sql.Connection;
  47. import java.util.List;
  48. import java.util.Map;

  49. import org.slf4j.Logger;
  50. import org.openspcoop2.utils.sql.ISQLQueryObject;

  51. /**    
  52.  * Service can be used to search for the backend objects of type {@link org.openspcoop2.core.statistiche.StatisticaInfo}
  53.  *
  54.  * @author Poli Andrea (poli@link.it)
  55.  * @author $Author$
  56.  * @version $Rev$, $Date$
  57. */
  58. public class JDBCStatisticaInfoServiceSearch implements IStatisticaInfoServiceSearch, IDBServiceUtilities<StatisticaInfo> {


  59.     protected JDBCServiceManagerProperties jdbcProperties = null;
  60.     protected JDBCServiceManager jdbcServiceManager = null;
  61.     protected Logger log = null;
  62.     protected IJDBCServiceSearchWithoutId<StatisticaInfo, JDBCServiceManager> serviceSearch = null;
  63.     protected JDBC_SQLObjectFactory jdbcSqlObjectFactory = null;
  64.     public JDBCStatisticaInfoServiceSearch(JDBCServiceManager jdbcServiceManager) throws ServiceException {
  65.         this.jdbcServiceManager = jdbcServiceManager;
  66.         this.jdbcProperties = jdbcServiceManager.getJdbcProperties();
  67.         this.log = jdbcServiceManager.getLog();
  68.         String msgInit = JDBCStatisticaInfoServiceSearch.class.getName()+ " initialized";
  69.         this.log.debug(msgInit);
  70.         this.serviceSearch = JDBCProperties.getInstance(org.openspcoop2.core.statistiche.dao.jdbc.JDBCServiceManager.class.getPackage(),ProjectInfo.getInstance()).getServiceSearch("statisticaInfo");
  71.         this.serviceSearch.setServiceManager(new JDBCLimitedServiceManager(this.jdbcServiceManager));
  72.         this.jdbcSqlObjectFactory = new JDBC_SQLObjectFactory();
  73.     }
  74.    
  75.     protected void logError(Exception e) {
  76.         if(e!=null && this.log!=null) {
  77.             this.log.error(e.getMessage(),e);
  78.         }
  79.     }
  80.     protected void logDebug(Exception e) {
  81.         if(e!=null && this.log!=null) {
  82.             this.log.debug(e.getMessage(),e);
  83.         }
  84.     }
  85.     protected void logJDBCExpression(JDBCExpression jdbcExpression) throws ExpressionException{
  86.         if(this.log!=null) {
  87.             String msgDebug = "sql = "+jdbcExpression.toSql();
  88.             this.log.debug(msgDebug);
  89.         }
  90.     }
  91.     protected void logJDBCPaginatedExpression(JDBCPaginatedExpression jdbcPaginatedExpression) throws ExpressionException{
  92.         if(this.log!=null) {
  93.             String msgDebug = "sql = "+jdbcPaginatedExpression.toSql();
  94.             this.log.debug(msgDebug);
  95.         }
  96.     }
  97.    
  98.     private static final String PARAMETER_TYPE_PREFIX = "Parameter (type:";
  99.        
  100.     private ServiceException newServiceExceptionParameterIdMappingResolutionBehaviourIsNull(){
  101.         return new ServiceException(PARAMETER_TYPE_PREFIX+org.openspcoop2.generic_project.beans.IDMappingBehaviour.class.getName()+") 'idMappingResolutionBehaviour' is null");
  102.     }

  103.     protected ServiceException newServiceExceptionParameterExpressionWrongType(IExpression expression){
  104.         return new ServiceException(PARAMETER_TYPE_PREFIX+expression.getClass().getName()+") 'expression' has wrong type, expect "+JDBCExpression.class.getName());
  105.     }
  106.     protected ServiceException newServiceExceptionParameterExpressionIsNull(){
  107.         return new ServiceException(PARAMETER_TYPE_PREFIX+IExpression.class.getName()+") 'expression' is null");
  108.     }
  109.    
  110.     private ServiceException newServiceExceptionParameterPaginatedExpressionIsNull(){
  111.         return new ServiceException(PARAMETER_TYPE_PREFIX+IPaginatedExpression.class.getName()+") 'expression' is null");
  112.     }
  113.     private ServiceException newServiceExceptionParameterPaginatedExpressionIsNullErrorParameterPaginated(){
  114.         return new ServiceException(PARAMETER_TYPE_PREFIX+IPaginatedExpression.class.getName()+") 'paginatedExpression' is null");
  115.     }
  116.     private ServiceException newServiceExceptionParameterPaginatedExpressionWrongType(IPaginatedExpression expression){
  117.         return new ServiceException(PARAMETER_TYPE_PREFIX+expression.getClass().getName()+") 'expression' has wrong type, expect "+JDBCPaginatedExpression.class.getName());
  118.     }
  119.     private ServiceException newServiceExceptionParameterPaginatedExpressionWrongTypeErrorParameterPaginated(IPaginatedExpression paginatedExpression){
  120.         return new ServiceException(PARAMETER_TYPE_PREFIX+paginatedExpression.getClass().getName()+") 'paginatedExpression' has wrong type, expect "+JDBCPaginatedExpression.class.getName());
  121.     }
  122.    
  123.     private ServiceException newServiceExceptionParameterUnionExpressionIsNull(){
  124.         return new ServiceException(PARAMETER_TYPE_PREFIX+UnionExpression.class.getName()+") 'unionExpression' is null");
  125.     }
  126.    
  127.    
  128.     @Override
  129.     public void validate(StatisticaInfo statisticaInfo) throws ServiceException,
  130.             ValidationException, NotImplementedException {
  131.         org.openspcoop2.generic_project.utils.XSDValidator.validate(statisticaInfo, this.log,
  132.                 org.openspcoop2.core.statistiche.utils.XSDValidator.getXSDValidator(this.log));
  133.     }
  134.    
  135.     @Override
  136.     public IJDBCFetch getFetch() {
  137.         return this.serviceSearch.getFetch();
  138.     }

  139.     @Override
  140.     public ISQLFieldConverter getFieldConverter() {
  141.         return this.serviceSearch.getFieldConverter();
  142.     }
  143.    
  144.        


  145.    

  146.     @Override
  147.     public List<StatisticaInfo> findAll(IPaginatedExpression expression) throws ServiceException, NotImplementedException {

  148.         Connection connection = null;
  149.         try{
  150.            
  151.             // check parameters
  152.             if(expression==null){
  153.                 throw this.newServiceExceptionParameterPaginatedExpressionIsNull();
  154.             }
  155.             if( ! (expression instanceof JDBCPaginatedExpression) ){
  156.                 throw this.newServiceExceptionParameterPaginatedExpressionWrongType(expression);
  157.             }
  158.             JDBCPaginatedExpression jdbcPaginatedExpression = (JDBCPaginatedExpression) expression;
  159.             logJDBCPaginatedExpression(jdbcPaginatedExpression);

  160.             // ISQLQueryObject
  161.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  162.             sqlQueryObject.setANDLogicOperator(true);
  163.             // Connection sql
  164.             connection = this.jdbcServiceManager.getConnection();

  165.             return this.serviceSearch.findAll(this.jdbcProperties,this.log,connection,sqlQueryObject,jdbcPaginatedExpression,null);        
  166.    
  167.         }catch(ServiceException | NotImplementedException e){
  168.             this.logError(e); throw e;
  169.         }catch(Exception e){
  170.             this.logError(e); throw new ServiceException("FindAll not completed: "+e.getMessage(),e);
  171.         }finally{
  172.             if(connection!=null){
  173.                 this.jdbcServiceManager.closeConnection(connection);
  174.             }
  175.         }
  176.        
  177.     }
  178.    
  179.     @Override
  180.     public List<StatisticaInfo> findAll(IPaginatedExpression expression, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws ServiceException, NotImplementedException {

  181.         Connection connection = null;
  182.         try{
  183.            
  184.             // check parameters
  185.             if(idMappingResolutionBehaviour==null){
  186.                 throw this.newServiceExceptionParameterIdMappingResolutionBehaviourIsNull();
  187.             }
  188.             if(expression==null){
  189.                 throw this.newServiceExceptionParameterPaginatedExpressionIsNull();
  190.             }
  191.             if( ! (expression instanceof JDBCPaginatedExpression) ){
  192.                 throw this.newServiceExceptionParameterPaginatedExpressionWrongType(expression);
  193.             }
  194.             JDBCPaginatedExpression jdbcPaginatedExpression = (JDBCPaginatedExpression) expression;
  195.             logJDBCPaginatedExpression(jdbcPaginatedExpression);

  196.             // ISQLQueryObject
  197.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  198.             sqlQueryObject.setANDLogicOperator(true);
  199.             // Connection sql
  200.             connection = this.jdbcServiceManager.getConnection();

  201.             return this.serviceSearch.findAll(this.jdbcProperties,this.log,connection,sqlQueryObject,jdbcPaginatedExpression,idMappingResolutionBehaviour);        
  202.    
  203.         }catch(ServiceException | NotImplementedException e){
  204.             this.logError(e); throw e;
  205.         }catch(Exception e){
  206.             this.logError(e); throw new ServiceException("FindAll not completed: "+e.getMessage(),e);
  207.         }finally{
  208.             if(connection!=null){
  209.                 this.jdbcServiceManager.closeConnection(connection);
  210.             }
  211.         }
  212.        
  213.     }

  214.     @Override
  215.     public StatisticaInfo find(IExpression expression) throws ServiceException, NotFoundException, MultipleResultException, NotImplementedException {

  216.         Connection connection = null;
  217.         try{
  218.            
  219.             // check parameters
  220.             if(expression==null){
  221.                 throw this.newServiceExceptionParameterExpressionIsNull();
  222.             }
  223.             if( ! (expression instanceof JDBCExpression) ){
  224.                 throw this.newServiceExceptionParameterExpressionWrongType(expression);
  225.             }
  226.             JDBCExpression jdbcExpression = (JDBCExpression) expression;
  227.             this.logJDBCExpression(jdbcExpression);

  228.             // ISQLQueryObject
  229.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  230.             sqlQueryObject.setANDLogicOperator(true);
  231.             // Connection sql
  232.             connection = this.jdbcServiceManager.getConnection();

  233.             return this.serviceSearch.find(this.jdbcProperties,this.log,connection,sqlQueryObject,jdbcExpression,null);        

  234.         }catch(ServiceException | MultipleResultException | NotImplementedException e){
  235.             this.logError(e); throw e;
  236.         }catch(NotFoundException e){
  237.             this.logDebug(e); throw e;
  238.         }catch(Exception e){
  239.             this.logError(e); throw new ServiceException("Find not completed: "+e.getMessage(),e);
  240.         }finally{
  241.             if(connection!=null){
  242.                 this.jdbcServiceManager.closeConnection(connection);
  243.             }
  244.         }
  245.        
  246.     }
  247.    
  248.     @Override
  249.     public StatisticaInfo find(IExpression expression, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws ServiceException, NotFoundException, MultipleResultException, NotImplementedException {

  250.         Connection connection = null;
  251.         try{
  252.            
  253.             // check parameters
  254.             if(idMappingResolutionBehaviour==null){
  255.                 throw this.newServiceExceptionParameterIdMappingResolutionBehaviourIsNull();
  256.             }
  257.             if(expression==null){
  258.                 throw this.newServiceExceptionParameterExpressionIsNull();
  259.             }
  260.             if( ! (expression instanceof JDBCExpression) ){
  261.                 throw this.newServiceExceptionParameterExpressionWrongType(expression);
  262.             }
  263.             JDBCExpression jdbcExpression = (JDBCExpression) expression;
  264.             this.logJDBCExpression(jdbcExpression);

  265.             // ISQLQueryObject
  266.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  267.             sqlQueryObject.setANDLogicOperator(true);
  268.             // Connection sql
  269.             connection = this.jdbcServiceManager.getConnection();

  270.             return this.serviceSearch.find(this.jdbcProperties,this.log,connection,sqlQueryObject,jdbcExpression,idMappingResolutionBehaviour);        

  271.         }catch(ServiceException | MultipleResultException | NotImplementedException e){
  272.             this.logError(e); throw e;
  273.         }catch(NotFoundException e){
  274.             this.logDebug(e); throw e;
  275.         }catch(Exception e){
  276.             this.logError(e); throw new ServiceException("Find not completed: "+e.getMessage(),e);
  277.         }finally{
  278.             if(connection!=null){
  279.                 this.jdbcServiceManager.closeConnection(connection);
  280.             }
  281.         }
  282.        
  283.     }

  284.     @Override
  285.     public NonNegativeNumber count(IExpression expression) throws ServiceException, NotImplementedException {

  286.         Connection connection = null;
  287.         try{
  288.            
  289.             // check parameters
  290.             if(expression==null){
  291.                 throw this.newServiceExceptionParameterExpressionIsNull();
  292.             }
  293.             if( ! (expression instanceof JDBCExpression) ){
  294.                 throw this.newServiceExceptionParameterExpressionWrongType(expression);
  295.             }
  296.             JDBCExpression jdbcExpression = (JDBCExpression) expression;
  297.             this.logJDBCExpression(jdbcExpression);
  298.            
  299.             // ISQLQueryObject
  300.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  301.             sqlQueryObject.setANDLogicOperator(true);
  302.             // Connection sql
  303.             connection = this.jdbcServiceManager.getConnection();

  304.             return this.serviceSearch.count(this.jdbcProperties,this.log,connection,sqlQueryObject,jdbcExpression);
  305.    
  306.         }catch(ServiceException | NotImplementedException e){
  307.             this.logError(e); throw e;
  308.         }catch(Exception e){
  309.             this.logError(e); throw new ServiceException("Count not completed: "+e.getMessage(),e);
  310.         }finally{
  311.             if(connection!=null){
  312.                 this.jdbcServiceManager.closeConnection(connection);
  313.             }
  314.         }
  315.        
  316.     }

  317.    
  318.     @Override
  319.     public List<Object> select(IPaginatedExpression paginatedExpression, IField field) throws ServiceException,NotFoundException,NotImplementedException {
  320.    
  321.         Connection connection = null;
  322.         try{
  323.            
  324.             // check parameters
  325.             if(paginatedExpression==null){
  326.                 throw this.newServiceExceptionParameterPaginatedExpressionIsNullErrorParameterPaginated();
  327.             }
  328.             if( ! (paginatedExpression instanceof JDBCPaginatedExpression) ){
  329.                 throw this.newServiceExceptionParameterPaginatedExpressionWrongTypeErrorParameterPaginated(paginatedExpression);
  330.             }
  331.             JDBCPaginatedExpression jdbcPaginatedExpression = (JDBCPaginatedExpression) paginatedExpression;
  332.             logJDBCPaginatedExpression(jdbcPaginatedExpression);

  333.             // ISQLQueryObject
  334.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  335.             sqlQueryObject.setANDLogicOperator(true);
  336.             // Connection sql
  337.             connection = this.jdbcServiceManager.getConnection();

  338.             return this.serviceSearch.select(this.jdbcProperties,this.log,connection,sqlQueryObject,jdbcPaginatedExpression,field);        
  339.    
  340.         }catch(ServiceException | NotImplementedException e){
  341.             this.logError(e); throw e;
  342.         }catch(NotFoundException e){
  343.             this.logDebug(e); throw e;
  344.         }catch(Exception e){
  345.             this.logError(e); throw new ServiceException("Select 'field' not completed: "+e.getMessage(),e);
  346.         }finally{
  347.             if(connection!=null){
  348.                 this.jdbcServiceManager.closeConnection(connection);
  349.             }
  350.         }
  351.    
  352.     }
  353.    
  354.     @Override
  355.     public List<Object> select(IPaginatedExpression paginatedExpression, boolean distinct, IField field) throws ServiceException,NotFoundException,NotImplementedException {

  356.         Connection connection = null;
  357.         try{
  358.            
  359.             // check parameters
  360.             if(paginatedExpression==null){
  361.                 throw this.newServiceExceptionParameterPaginatedExpressionIsNullErrorParameterPaginated();
  362.             }
  363.             if( ! (paginatedExpression instanceof JDBCPaginatedExpression) ){
  364.                 throw this.newServiceExceptionParameterPaginatedExpressionWrongTypeErrorParameterPaginated(paginatedExpression);
  365.             }
  366.             JDBCPaginatedExpression jdbcPaginatedExpression = (JDBCPaginatedExpression) paginatedExpression;
  367.             logJDBCPaginatedExpression(jdbcPaginatedExpression);

  368.             // ISQLQueryObject
  369.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  370.             sqlQueryObject.setANDLogicOperator(true);
  371.             // Connection sql
  372.             connection = this.jdbcServiceManager.getConnection();

  373.             return this.serviceSearch.select(this.jdbcProperties,this.log,connection,sqlQueryObject,jdbcPaginatedExpression,distinct,field);            
  374.    
  375.         }catch(ServiceException | NotImplementedException e){
  376.             this.logError(e); throw e;
  377.         }catch(NotFoundException e){
  378.             this.logDebug(e); throw e;
  379.         }catch(Exception e){
  380.             this.logError(e); throw new ServiceException("Select 'distinct:"+distinct+"' field not completed: "+e.getMessage(),e);
  381.         }finally{
  382.             if(connection!=null){
  383.                 this.jdbcServiceManager.closeConnection(connection);
  384.             }
  385.         }
  386.        
  387.     }
  388.    
  389.     @Override
  390.     public List<Map<String,Object>> select(IPaginatedExpression paginatedExpression, IField ... field) throws ServiceException,NotFoundException,NotImplementedException {
  391.    
  392.         Connection connection = null;
  393.         try{
  394.            
  395.             // check parameters
  396.             if(paginatedExpression==null){
  397.                 throw this.newServiceExceptionParameterPaginatedExpressionIsNullErrorParameterPaginated();
  398.             }
  399.             if( ! (paginatedExpression instanceof JDBCPaginatedExpression) ){
  400.                 throw this.newServiceExceptionParameterPaginatedExpressionWrongTypeErrorParameterPaginated(paginatedExpression);
  401.             }
  402.             JDBCPaginatedExpression jdbcPaginatedExpression = (JDBCPaginatedExpression) paginatedExpression;
  403.             logJDBCPaginatedExpression(jdbcPaginatedExpression);

  404.             // ISQLQueryObject
  405.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  406.             sqlQueryObject.setANDLogicOperator(true);
  407.             // Connection sql
  408.             connection = this.jdbcServiceManager.getConnection();

  409.             return this.serviceSearch.select(this.jdbcProperties,this.log,connection,sqlQueryObject,jdbcPaginatedExpression,field);        
  410.    
  411.         }catch(ServiceException | NotImplementedException e){
  412.             this.logError(e); throw e;
  413.         }catch(NotFoundException e){
  414.             this.logDebug(e); throw e;
  415.         }catch(Exception e){
  416.             this.logError(e); throw new ServiceException("Select not completed: "+e.getMessage(),e);
  417.         }finally{
  418.             if(connection!=null){
  419.                 this.jdbcServiceManager.closeConnection(connection);
  420.             }
  421.         }
  422.    
  423.     }
  424.     @Override
  425.     public List<Map<String,Object>> select(IPaginatedExpression paginatedExpression, boolean distinct, IField ... field) throws ServiceException,NotFoundException,NotImplementedException {

  426.         Connection connection = null;
  427.         try{
  428.            
  429.             // check parameters
  430.             if(paginatedExpression==null){
  431.                 throw this.newServiceExceptionParameterPaginatedExpressionIsNullErrorParameterPaginated();
  432.             }
  433.             if( ! (paginatedExpression instanceof JDBCPaginatedExpression) ){
  434.                 throw this.newServiceExceptionParameterPaginatedExpressionWrongTypeErrorParameterPaginated(paginatedExpression);
  435.             }
  436.             JDBCPaginatedExpression jdbcPaginatedExpression = (JDBCPaginatedExpression) paginatedExpression;
  437.             logJDBCPaginatedExpression(jdbcPaginatedExpression);

  438.             // ISQLQueryObject
  439.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  440.             sqlQueryObject.setANDLogicOperator(true);
  441.             // Connection sql
  442.             connection = this.jdbcServiceManager.getConnection();

  443.             return this.serviceSearch.select(this.jdbcProperties,this.log,connection,sqlQueryObject,jdbcPaginatedExpression,distinct,field);            
  444.    
  445.         }catch(ServiceException | NotImplementedException e){
  446.             this.logError(e); throw e;
  447.         }catch(NotFoundException e){
  448.             this.logDebug(e); throw e;
  449.         }catch(Exception e){
  450.             this.logError(e); throw new ServiceException("Select distinct:"+distinct+" not completed: "+e.getMessage(),e);
  451.         }finally{
  452.             if(connection!=null){
  453.                 this.jdbcServiceManager.closeConnection(connection);
  454.             }
  455.         }
  456.        
  457.     }
  458.    
  459.     @Override
  460.     public Object aggregate(IExpression expression, FunctionField functionField) throws ServiceException,NotFoundException,NotImplementedException {

  461.         Connection connection = null;
  462.         try{
  463.            
  464.             // check parameters
  465.             if(expression==null){
  466.                 throw this.newServiceExceptionParameterExpressionIsNull();
  467.             }
  468.             if( ! (expression instanceof JDBCExpression) ){
  469.                 throw this.newServiceExceptionParameterExpressionWrongType(expression);
  470.             }
  471.             JDBCExpression jdbcExpression = (JDBCExpression) expression;
  472.             this.logJDBCExpression(jdbcExpression);

  473.             // ISQLQueryObject
  474.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  475.             sqlQueryObject.setANDLogicOperator(true);
  476.             // Connection sql
  477.             connection = this.jdbcServiceManager.getConnection();

  478.             return this.serviceSearch.aggregate(this.jdbcProperties,this.log,connection,sqlQueryObject,jdbcExpression,functionField);          
  479.    
  480.         }catch(ServiceException | NotImplementedException e){
  481.             this.logError(e); throw e;
  482.         }catch(NotFoundException e){
  483.             this.logDebug(e); throw e;
  484.         }catch(Exception e){
  485.             this.logError(e); throw new ServiceException("Aggregate not completed: "+e.getMessage(),e);
  486.         }finally{
  487.             if(connection!=null){
  488.                 this.jdbcServiceManager.closeConnection(connection);
  489.             }
  490.         }
  491.        
  492.     }
  493.    
  494.     @Override
  495.     public Map<String,Object> aggregate(IExpression expression, FunctionField ... functionField) throws ServiceException,NotFoundException,NotImplementedException {

  496.         Connection connection = null;
  497.         try{
  498.            
  499.             // check parameters
  500.             if(expression==null){
  501.                 throw this.newServiceExceptionParameterExpressionIsNull();
  502.             }
  503.             if( ! (expression instanceof JDBCExpression) ){
  504.                 throw this.newServiceExceptionParameterExpressionWrongType(expression);
  505.             }
  506.             JDBCExpression jdbcExpression = (JDBCExpression) expression;
  507.             this.logJDBCExpression(jdbcExpression);

  508.             // ISQLQueryObject
  509.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  510.             sqlQueryObject.setANDLogicOperator(true);
  511.             // Connection sql
  512.             connection = this.jdbcServiceManager.getConnection();

  513.             return this.serviceSearch.aggregate(this.jdbcProperties,this.log,connection,sqlQueryObject,jdbcExpression,functionField);          
  514.    
  515.         }catch(ServiceException | NotImplementedException e){
  516.             this.logError(e); throw e;
  517.         }catch(NotFoundException e){
  518.             this.logDebug(e); throw e;
  519.         }catch(Exception e){
  520.             this.logError(e); throw new ServiceException("Aggregate not completed: "+e.getMessage(),e);
  521.         }finally{
  522.             if(connection!=null){
  523.                 this.jdbcServiceManager.closeConnection(connection);
  524.             }
  525.         }
  526.        
  527.     }
  528.    
  529.     @Override
  530.     public List<Map<String,Object>> groupBy(IExpression expression, FunctionField ... functionField) throws ServiceException,NotFoundException,NotImplementedException {

  531.         Connection connection = null;
  532.         try{
  533.            
  534.             // check parameters
  535.             if(expression==null){
  536.                 throw this.newServiceExceptionParameterExpressionIsNull();
  537.             }
  538.             if( ! (expression instanceof JDBCExpression) ){
  539.                 throw this.newServiceExceptionParameterExpressionWrongType(expression);
  540.             }
  541.             JDBCExpression jdbcExpression = (JDBCExpression) expression;
  542.             this.logJDBCExpression(jdbcExpression);

  543.             // ISQLQueryObject
  544.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  545.             sqlQueryObject.setANDLogicOperator(true);
  546.             // Connection sql
  547.             connection = this.jdbcServiceManager.getConnection();

  548.             return this.serviceSearch.groupBy(this.jdbcProperties,this.log,connection,sqlQueryObject,jdbcExpression,functionField);        
  549.    
  550.         }catch(ServiceException | NotImplementedException e){
  551.             this.logError(e); throw e;
  552.         }catch(NotFoundException e){
  553.             this.logDebug(e); throw e;
  554.         }catch(Exception e){
  555.             this.logError(e); throw new ServiceException("GroupBy not completed: "+e.getMessage(),e);
  556.         }finally{
  557.             if(connection!=null){
  558.                 this.jdbcServiceManager.closeConnection(connection);
  559.             }
  560.         }
  561.        
  562.     }
  563.    
  564.     @Override
  565.     public List<Map<String,Object>> groupBy(IPaginatedExpression paginatedExpression, FunctionField ... functionField) throws ServiceException,NotFoundException,NotImplementedException {

  566.         Connection connection = null;
  567.         try{
  568.            
  569.             // check parameters
  570.             if(paginatedExpression==null){
  571.                 throw this.newServiceExceptionParameterPaginatedExpressionIsNullErrorParameterPaginated();
  572.             }
  573.             if( ! (paginatedExpression instanceof JDBCPaginatedExpression) ){
  574.                 throw this.newServiceExceptionParameterPaginatedExpressionWrongTypeErrorParameterPaginated(paginatedExpression);
  575.             }
  576.             JDBCPaginatedExpression jdbcPaginatedExpression = (JDBCPaginatedExpression) paginatedExpression;
  577.             logJDBCPaginatedExpression(jdbcPaginatedExpression);

  578.             // ISQLQueryObject
  579.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  580.             sqlQueryObject.setANDLogicOperator(true);
  581.             // Connection sql
  582.             connection = this.jdbcServiceManager.getConnection();

  583.             return this.serviceSearch.groupBy(this.jdbcProperties,this.log,connection,sqlQueryObject,jdbcPaginatedExpression,functionField);            
  584.    
  585.         }catch(ServiceException | NotImplementedException e){
  586.             this.logError(e); throw e;
  587.         }catch(NotFoundException e){
  588.             this.logDebug(e); throw e;
  589.         }catch(Exception e){
  590.             this.logError(e); throw new ServiceException("GroupBy not completed: "+e.getMessage(),e);
  591.         }finally{
  592.             if(connection!=null){
  593.                 this.jdbcServiceManager.closeConnection(connection);
  594.             }
  595.         }
  596.        
  597.     }
  598.    
  599.     @Override
  600.     public List<Map<String,Object>> union(Union union, UnionExpression ... unionExpression) throws ServiceException,NotFoundException,NotImplementedException {

  601.         Connection connection = null;
  602.         try{
  603.            
  604.             // check parameters
  605.             if(unionExpression==null){
  606.                 throw this.newServiceExceptionParameterUnionExpressionIsNull();
  607.             }
  608.            
  609.             // ISQLQueryObject
  610.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  611.             sqlQueryObject.setANDLogicOperator(true);
  612.             // Connection sql
  613.             connection = this.jdbcServiceManager.getConnection();

  614.             return this.serviceSearch.union(this.jdbcProperties,this.log,connection,sqlQueryObject,union,unionExpression);          
  615.    
  616.         }catch(ServiceException | NotImplementedException e){
  617.             this.logError(e); throw e;
  618.         }catch(NotFoundException e){
  619.             this.logDebug(e); throw e;
  620.         }catch(Exception e){
  621.             this.logError(e); throw new ServiceException("Union not completed: "+e.getMessage(),e);
  622.         }finally{
  623.             if(connection!=null){
  624.                 this.jdbcServiceManager.closeConnection(connection);
  625.             }
  626.         }
  627.        
  628.     }
  629.    
  630.     @Override
  631.     public NonNegativeNumber unionCount(Union union, UnionExpression ... unionExpression) throws ServiceException,NotFoundException,NotImplementedException {

  632.         Connection connection = null;
  633.         try{
  634.            
  635.             // check parameters
  636.             if(unionExpression==null){
  637.                 throw this.newServiceExceptionParameterUnionExpressionIsNull();
  638.             }
  639.            
  640.             // ISQLQueryObject
  641.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  642.             sqlQueryObject.setANDLogicOperator(true);
  643.             // Connection sql
  644.             connection = this.jdbcServiceManager.getConnection();

  645.             return this.serviceSearch.unionCount(this.jdbcProperties,this.log,connection,sqlQueryObject,union,unionExpression);        
  646.    
  647.         }catch(ServiceException | NotImplementedException e){
  648.             this.logError(e); throw e;
  649.         }catch(NotFoundException e){
  650.             this.logDebug(e); throw e;
  651.         }catch(Exception e){
  652.             this.logError(e); throw new ServiceException("UnionCount not completed: "+e.getMessage(),e);
  653.         }finally{
  654.             if(connection!=null){
  655.                 this.jdbcServiceManager.closeConnection(connection);
  656.             }
  657.         }
  658.        
  659.     }

  660.     @Override
  661.     public IExpression newExpression() throws ServiceException,NotImplementedException {

  662.         return this.serviceSearch.newExpression(this.log);

  663.     }

  664.     @Override
  665.     public IPaginatedExpression newPaginatedExpression() throws ServiceException, NotImplementedException {

  666.         return this.serviceSearch.newPaginatedExpression(this.log);

  667.     }
  668.    
  669.     @Override
  670.     public IExpression toExpression(IPaginatedExpression paginatedExpression) throws ServiceException,NotImplementedException {

  671.         return this.serviceSearch.toExpression((JDBCPaginatedExpression)paginatedExpression,this.log);

  672.     }

  673.     @Override
  674.     public IPaginatedExpression toPaginatedExpression(IExpression expression) throws ServiceException, NotImplementedException {

  675.         return this.serviceSearch.toPaginatedExpression((JDBCExpression)expression,this.log);

  676.     }
  677.    

  678.    
  679.     @Override
  680.     public List<List<Object>> nativeQuery(String sql,List<Class<?>> returnClassTypes,Object ... param) throws ServiceException,NotFoundException,NotImplementedException{
  681.    
  682.         Connection connection = null;
  683.         try{
  684.            
  685.             // check parameters
  686.             if(returnClassTypes==null || returnClassTypes.isEmpty()){
  687.                 throw new ServiceException("Parameter 'returnClassTypes' is less equals 0");
  688.             }
  689.            
  690.             // ISQLQueryObject
  691.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  692.             sqlQueryObject.setANDLogicOperator(true);
  693.             // Connection sql
  694.             connection = this.jdbcServiceManager.getConnection();

  695.             return this.serviceSearch.nativeQuery(this.jdbcProperties,this.log,connection,sqlQueryObject,sql,returnClassTypes,param);      
  696.    
  697.         }catch(ServiceException | NotImplementedException e){
  698.             this.logError(e); throw e;
  699.         }catch(NotFoundException e){
  700.             this.logDebug(e); throw e;
  701.         }catch(Exception e){
  702.             this.logError(e); throw new ServiceException("nativeQuery not completed: "+e.getMessage(),e);
  703.         }finally{
  704.             if(connection!=null){
  705.                 this.jdbcServiceManager.closeConnection(connection);
  706.             }
  707.         }
  708.    
  709.     }
  710.    
  711. }