JDBCStatisticaOrariaServiceSearch.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.InUse;
  24. import org.openspcoop2.generic_project.beans.IField;
  25. import org.openspcoop2.generic_project.beans.NonNegativeNumber;
  26. import org.openspcoop2.generic_project.beans.UnionExpression;
  27. import org.openspcoop2.generic_project.beans.Union;
  28. import org.openspcoop2.generic_project.beans.FunctionField;
  29. import org.openspcoop2.generic_project.dao.jdbc.JDBCServiceManagerProperties;
  30. import org.openspcoop2.generic_project.exception.ExpressionException;
  31. import org.openspcoop2.generic_project.exception.MultipleResultException;
  32. import org.openspcoop2.generic_project.exception.NotFoundException;
  33. import org.openspcoop2.generic_project.exception.NotImplementedException;
  34. import org.openspcoop2.generic_project.exception.ServiceException;
  35. import org.openspcoop2.generic_project.exception.ValidationException;
  36. import org.openspcoop2.generic_project.expression.IExpression;
  37. import org.openspcoop2.generic_project.expression.IPaginatedExpression;
  38. import org.openspcoop2.generic_project.expression.impl.sql.ISQLFieldConverter;
  39. import org.openspcoop2.generic_project.dao.jdbc.JDBCExpression;
  40. import org.openspcoop2.generic_project.dao.jdbc.JDBCPaginatedExpression;
  41. import org.openspcoop2.generic_project.dao.jdbc.JDBCProperties;
  42. import org.openspcoop2.generic_project.dao.jdbc.utils.IJDBCFetch;
  43. import org.openspcoop2.generic_project.dao.jdbc.utils.JDBC_SQLObjectFactory;

  44. import org.openspcoop2.core.statistiche.StatisticaOraria;
  45. import org.openspcoop2.core.statistiche.dao.IDBStatisticaOrariaServiceSearch;
  46. import org.openspcoop2.core.statistiche.utils.ProjectInfo;

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

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

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


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

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

  143.     @Override
  144.     public ISQLFieldConverter getFieldConverter() {
  145.         return this.serviceSearch.getFieldConverter();
  146.     }
  147.    
  148.        


  149.    

  150.     @Override
  151.     public List<StatisticaOraria> findAll(IPaginatedExpression expression) throws ServiceException, NotImplementedException {

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

  164.             // ISQLQueryObject
  165.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  166.             sqlQueryObject.setANDLogicOperator(true);
  167.             // Connection sql
  168.             connection = this.jdbcServiceManager.getConnection();

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

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

  200.             // ISQLQueryObject
  201.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  202.             sqlQueryObject.setANDLogicOperator(true);
  203.             // Connection sql
  204.             connection = this.jdbcServiceManager.getConnection();

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

  218.     @Override
  219.     public StatisticaOraria find(IExpression expression) throws ServiceException, NotFoundException, MultipleResultException, NotImplementedException {

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

  232.             // ISQLQueryObject
  233.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  234.             sqlQueryObject.setANDLogicOperator(true);
  235.             // Connection sql
  236.             connection = this.jdbcServiceManager.getConnection();

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

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

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

  269.             // ISQLQueryObject
  270.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  271.             sqlQueryObject.setANDLogicOperator(true);
  272.             // Connection sql
  273.             connection = this.jdbcServiceManager.getConnection();

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

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

  288.     @Override
  289.     public NonNegativeNumber count(IExpression expression) throws ServiceException, NotImplementedException {

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

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

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

  337.             // ISQLQueryObject
  338.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  339.             sqlQueryObject.setANDLogicOperator(true);
  340.             // Connection sql
  341.             connection = this.jdbcServiceManager.getConnection();

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

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

  372.             // ISQLQueryObject
  373.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  374.             sqlQueryObject.setANDLogicOperator(true);
  375.             // Connection sql
  376.             connection = this.jdbcServiceManager.getConnection();

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

  408.             // ISQLQueryObject
  409.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  410.             sqlQueryObject.setANDLogicOperator(true);
  411.             // Connection sql
  412.             connection = this.jdbcServiceManager.getConnection();

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

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

  442.             // ISQLQueryObject
  443.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  444.             sqlQueryObject.setANDLogicOperator(true);
  445.             // Connection sql
  446.             connection = this.jdbcServiceManager.getConnection();

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

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

  477.             // ISQLQueryObject
  478.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  479.             sqlQueryObject.setANDLogicOperator(true);
  480.             // Connection sql
  481.             connection = this.jdbcServiceManager.getConnection();

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

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

  512.             // ISQLQueryObject
  513.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  514.             sqlQueryObject.setANDLogicOperator(true);
  515.             // Connection sql
  516.             connection = this.jdbcServiceManager.getConnection();

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

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

  547.             // ISQLQueryObject
  548.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  549.             sqlQueryObject.setANDLogicOperator(true);
  550.             // Connection sql
  551.             connection = this.jdbcServiceManager.getConnection();

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

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

  582.             // ISQLQueryObject
  583.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  584.             sqlQueryObject.setANDLogicOperator(true);
  585.             // Connection sql
  586.             connection = this.jdbcServiceManager.getConnection();

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

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

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

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

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

  664.     @Override
  665.     public IExpression newExpression() throws ServiceException,NotImplementedException {

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

  667.     }

  668.     @Override
  669.     public IPaginatedExpression newPaginatedExpression() throws ServiceException, NotImplementedException {

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

  671.     }
  672.    
  673.     @Override
  674.     public IExpression toExpression(IPaginatedExpression paginatedExpression) throws ServiceException,NotImplementedException {

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

  676.     }

  677.     @Override
  678.     public IPaginatedExpression toPaginatedExpression(IExpression expression) throws ServiceException, NotImplementedException {

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

  680.     }
  681.    

  682.     // -- DB
  683.    
  684.        
  685.     @Override
  686.     public StatisticaOraria get(long tableId) throws ServiceException, NotFoundException,MultipleResultException, NotImplementedException {
  687.    
  688.         Connection connection = null;
  689.         try{
  690.            
  691.             // check parameters
  692.             if(tableId<=0){
  693.                 throw this.newServiceExceptionParameterTableIdLessEqualsZero();
  694.             }
  695.            
  696.             // ISQLQueryObject
  697.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  698.             sqlQueryObject.setANDLogicOperator(true);
  699.             // Connection sql
  700.             connection = this.jdbcServiceManager.getConnection();
  701.        
  702.             return this.serviceSearch.get(this.jdbcProperties,this.log,connection,sqlQueryObject,tableId,null);
  703.        
  704.         }catch(ServiceException | MultipleResultException | NotImplementedException e){
  705.             this.logError(e); throw e;
  706.         }catch(NotFoundException e){
  707.             this.logDebug(e); throw e;
  708.         }catch(Exception e){
  709.             this.logError(e); throw new ServiceException("Get(tableId) not completed: "+e.getMessage(),e);
  710.         }finally{
  711.             if(connection!=null){
  712.                 this.jdbcServiceManager.closeConnection(connection);
  713.             }
  714.         }
  715.    
  716.     }
  717.    
  718.     @Override
  719.     public StatisticaOraria get(long tableId,org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws ServiceException, NotFoundException,MultipleResultException, NotImplementedException {
  720.    
  721.         Connection connection = null;
  722.         try{
  723.            
  724.             // check parameters
  725.             if(tableId<=0){
  726.                 throw this.newServiceExceptionParameterTableIdLessEqualsZero();
  727.             }
  728.             if(idMappingResolutionBehaviour==null){
  729.                 throw this.newServiceExceptionParameterIdMappingResolutionBehaviourIsNull();
  730.             }
  731.            
  732.             // ISQLQueryObject
  733.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  734.             sqlQueryObject.setANDLogicOperator(true);
  735.             // Connection sql
  736.             connection = this.jdbcServiceManager.getConnection();
  737.        
  738.             return this.serviceSearch.get(this.jdbcProperties,this.log,connection,sqlQueryObject,tableId,idMappingResolutionBehaviour);
  739.        
  740.         }catch(ServiceException | MultipleResultException | NotImplementedException e){
  741.             this.logError(e); throw e;
  742.         }catch(NotFoundException e){
  743.             this.logDebug(e); throw e;
  744.         }catch(Exception e){
  745.             this.logError(e); throw new ServiceException("Get(tableId,idMappingResolutionBehaviour) not completed: "+e.getMessage(),e);
  746.         }finally{
  747.             if(connection!=null){
  748.                 this.jdbcServiceManager.closeConnection(connection);
  749.             }
  750.         }
  751.    
  752.     }
  753.    
  754.     @Override
  755.     public boolean exists(long tableId) throws MultipleResultException,ServiceException,NotImplementedException {

  756.         Connection connection = null;
  757.         try{
  758.            
  759.             // check parameters
  760.             if(tableId<=0){
  761.                 throw this.newServiceExceptionParameterTableIdLessEqualsZero();
  762.             }

  763.             // ISQLQueryObject
  764.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  765.             sqlQueryObject.setANDLogicOperator(true);
  766.             // Connection sql
  767.             connection = this.jdbcServiceManager.getConnection();

  768.             return this.serviceSearch.exists(this.jdbcProperties,this.log,connection,sqlQueryObject,tableId);          
  769.    
  770.         }catch(MultipleResultException | ServiceException | NotImplementedException e){
  771.             this.logError(e); throw e;
  772.         }catch(Exception e){
  773.             this.logError(e); throw new ServiceException("Exists(tableId) not completed: "+e.getMessage(),e);
  774.         }finally{
  775.             if(connection!=null){
  776.                 this.jdbcServiceManager.closeConnection(connection);
  777.             }
  778.         }
  779.        
  780.     }
  781.    
  782.     @Override
  783.     public List<Long> findAllTableIds(IPaginatedExpression expression) throws ServiceException, NotImplementedException {
  784.        
  785.         Connection connection = null;
  786.         try{
  787.            
  788.             // check parameters
  789.             if(expression==null){
  790.                 throw this.newServiceExceptionParameterPaginatedExpressionIsNull();
  791.             }
  792.             if( ! (expression instanceof JDBCPaginatedExpression) ){
  793.                 throw this.newServiceExceptionParameterPaginatedExpressionWrongType(expression);
  794.             }
  795.             JDBCPaginatedExpression jdbcPaginatedExpression = (JDBCPaginatedExpression) expression;
  796.             logJDBCPaginatedExpression(jdbcPaginatedExpression);

  797.             // ISQLQueryObject
  798.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  799.             sqlQueryObject.setANDLogicOperator(true);
  800.             // Connection sql
  801.             connection = this.jdbcServiceManager.getConnection();
  802.            
  803.             return this.serviceSearch.findAllTableIds(this.jdbcProperties,this.log,connection,sqlQueryObject,jdbcPaginatedExpression);
  804.    
  805.         }catch(ServiceException | NotImplementedException e){
  806.             this.logError(e); throw e;
  807.         }catch(Exception e){
  808.             this.logError(e); throw new ServiceException("findAllTableIds not completed: "+e.getMessage(),e);
  809.         }finally{
  810.             if(connection!=null){
  811.                 this.jdbcServiceManager.closeConnection(connection);
  812.             }
  813.         }
  814.        
  815.     }
  816.    
  817.     @Override
  818.     public long findTableId(IExpression expression) throws ServiceException, NotFoundException, MultipleResultException, NotImplementedException {
  819.    
  820.         Connection connection = null;
  821.         try{
  822.            
  823.             // check parameters
  824.             if(expression==null){
  825.                 throw this.newServiceExceptionParameterPaginatedExpressionIsNull();
  826.             }
  827.             if( ! (expression instanceof JDBCExpression) ){
  828.                 throw this.newServiceExceptionParameterExpressionWrongType(expression);
  829.             }
  830.             JDBCExpression jdbcExpression = (JDBCExpression) expression;
  831.             this.logJDBCExpression(jdbcExpression);

  832.             // ISQLQueryObject
  833.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  834.             sqlQueryObject.setANDLogicOperator(true);
  835.             // Connection sql
  836.             connection = this.jdbcServiceManager.getConnection();

  837.             return this.serviceSearch.findTableId(this.jdbcProperties,this.log,connection,sqlQueryObject,jdbcExpression);          

  838.         }catch(ServiceException | MultipleResultException | NotImplementedException e){
  839.             this.logError(e); throw e;
  840.         }catch(NotFoundException e){
  841.             this.logDebug(e); throw e;
  842.         }catch(Exception e){
  843.             this.logError(e); throw new ServiceException("findTableId not completed: "+e.getMessage(),e);
  844.         }finally{
  845.             if(connection!=null){
  846.                 this.jdbcServiceManager.closeConnection(connection);
  847.             }
  848.         }
  849.    
  850.     }
  851.    
  852.     @Override
  853.     public InUse inUse(long tableId) throws ServiceException, NotFoundException, NotImplementedException {
  854.    
  855.         Connection connection = null;
  856.         try{
  857.            
  858.             // check parameters
  859.             if(tableId<=0){
  860.                 throw this.newServiceExceptionParameterTableIdLessEqualsZero();
  861.             }
  862.            
  863.             // ISQLQueryObject
  864.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  865.             sqlQueryObject.setANDLogicOperator(true);
  866.             // Connection sql
  867.             connection = this.jdbcServiceManager.getConnection();

  868.             return this.serviceSearch.inUse(this.jdbcProperties,this.log,connection,sqlQueryObject,tableId);        
  869.    
  870.         }catch(ServiceException | NotImplementedException e){
  871.             this.logError(e); throw e;
  872.         }catch(NotFoundException e){
  873.             this.logDebug(e); throw e;
  874.         }catch(Exception e){
  875.             this.logError(e); throw new ServiceException("InUse(tableId) not completed: "+e.getMessage(),e);
  876.         }finally{
  877.             if(connection!=null){
  878.                 this.jdbcServiceManager.closeConnection(connection);
  879.             }
  880.         }
  881.    
  882.     }
  883.    
  884.    
  885.     @Override
  886.     public void disableSelectForUpdate() throws ServiceException,NotImplementedException {
  887.         this.jdbcSqlObjectFactory.setSelectForUpdate(false);
  888.     }

  889.     @Override
  890.     public void enableSelectForUpdate() throws ServiceException,NotImplementedException {
  891.         this.jdbcSqlObjectFactory.setSelectForUpdate(true);
  892.     }
  893.    
  894.    
  895.     @Override
  896.     public List<List<Object>> nativeQuery(String sql,List<Class<?>> returnClassTypes,Object ... param) throws ServiceException,NotFoundException,NotImplementedException{
  897.    
  898.         Connection connection = null;
  899.         try{
  900.            
  901.             // check parameters
  902.             if(returnClassTypes==null || returnClassTypes.isEmpty()){
  903.                 throw new ServiceException("Parameter 'returnClassTypes' is less equals 0");
  904.             }
  905.            
  906.             // ISQLQueryObject
  907.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  908.             sqlQueryObject.setANDLogicOperator(true);
  909.             // Connection sql
  910.             connection = this.jdbcServiceManager.getConnection();

  911.             return this.serviceSearch.nativeQuery(this.jdbcProperties,this.log,connection,sqlQueryObject,sql,returnClassTypes,param);      
  912.    
  913.         }catch(ServiceException | NotImplementedException e){
  914.             this.logError(e); throw e;
  915.         }catch(NotFoundException e){
  916.             this.logDebug(e); throw e;
  917.         }catch(Exception e){
  918.             this.logError(e); throw new ServiceException("nativeQuery not completed: "+e.getMessage(),e);
  919.         }finally{
  920.             if(connection!=null){
  921.                 this.jdbcServiceManager.closeConnection(connection);
  922.             }
  923.         }
  924.    
  925.     }
  926.    
  927. }