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.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.StatisticaInfo;
  45. import org.openspcoop2.core.statistiche.dao.IDBStatisticaInfoServiceSearch;
  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.StatisticaInfo}
  54.  *
  55.  * @author Poli Andrea (poli@link.it)
  56.  * @author Tommaso Burlon (tommaso.burlon@link.it)
  57.  * @author $Author$
  58.  * @version $Rev$, $Date$
  59. */
  60. public class JDBCStatisticaInfoServiceSearch implements IDBStatisticaInfoServiceSearch, IDBServiceUtilities<StatisticaInfo> {


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

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

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


  150.    

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  668.     }

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

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

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

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

  677.     }

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

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

  681.     }
  682.    

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

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

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

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

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

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

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

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

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

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

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