JDBCTransazioneServiceSearch.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.transazioni.dao.jdbc;

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

  45. import org.openspcoop2.core.transazioni.Transazione;
  46. import org.openspcoop2.core.transazioni.dao.ITransazioneServiceSearch;
  47. import org.openspcoop2.core.transazioni.utils.ProjectInfo;

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

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

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


  61.     protected JDBCServiceManagerProperties jdbcProperties = null;
  62.     protected JDBCServiceManager jdbcServiceManager = null;
  63.     protected Logger log = null;
  64.     protected IJDBCServiceSearchWithId<Transazione, String, JDBCServiceManager> serviceSearch = null;
  65.     protected JDBC_SQLObjectFactory jdbcSqlObjectFactory = null;
  66.     public JDBCTransazioneServiceSearch(JDBCServiceManager jdbcServiceManager) throws ServiceException {
  67.         this.jdbcServiceManager = jdbcServiceManager;
  68.         this.jdbcProperties = jdbcServiceManager.getJdbcProperties();
  69.         this.log = jdbcServiceManager.getLog();
  70.         String msgInit = JDBCTransazioneServiceSearch.class.getName()+ " initialized";
  71.         this.log.debug(msgInit);
  72.         this.serviceSearch = JDBCProperties.getInstance(org.openspcoop2.core.transazioni.dao.jdbc.JDBCServiceManager.class.getPackage(),ProjectInfo.getInstance()).getServiceSearch("transazione");
  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 newServiceExceptionParameterObjIsNull(){
  103.         return new ServiceException(PARAMETER_TYPE_PREFIX+Transazione.class.getName()+") 'obj' is null");
  104.     }
  105.     protected ServiceException newServiceExceptionParameterIdIsNull(){
  106.         return new ServiceException(PARAMETER_TYPE_PREFIX+String.class.getName()+") 'id' is null");
  107.     }
  108.     private ServiceException newServiceExceptionParameterIdMappingResolutionBehaviourIsNull(){
  109.         return new ServiceException(PARAMETER_TYPE_PREFIX+org.openspcoop2.generic_project.beans.IDMappingBehaviour.class.getName()+") 'idMappingResolutionBehaviour' is null");
  110.     }

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

  147.     @Override
  148.     public ISQLFieldConverter getFieldConverter() {
  149.         return this.serviceSearch.getFieldConverter();
  150.     }
  151.    
  152.     @Override
  153.     public String convertToId(Transazione obj)
  154.             throws ServiceException, NotImplementedException {
  155.        
  156.         Connection connection = null;
  157.         try{
  158.            
  159.             // check parameters
  160.             if(obj==null){
  161.                 throw this.newServiceExceptionParameterObjIsNull();
  162.             }
  163.            
  164.             // ISQLQueryObject
  165.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  166.             sqlQueryObject.setANDLogicOperator(true);
  167.             // Connection sql
  168.             connection = this.jdbcServiceManager.getConnection();
  169.        
  170.             return this.serviceSearch.convertToId(this.jdbcProperties,this.log,connection,sqlQueryObject,obj);
  171.        
  172.         }catch(ServiceException | NotImplementedException e){
  173.             this.logError(e); throw e;
  174.         }catch(Exception e){
  175.             this.logError(e); throw new ServiceException("ConvertToId 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 Transazione get(String id) throws ServiceException, NotFoundException,MultipleResultException, NotImplementedException {
  186.    
  187.         Connection connection = null;
  188.         try{
  189.            
  190.             // check parameters
  191.             if(id==null){
  192.                 throw this.newServiceExceptionParameterIdIsNull();
  193.             }
  194.            
  195.             // ISQLQueryObject
  196.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  197.             sqlQueryObject.setANDLogicOperator(true);
  198.             // Connection sql
  199.             connection = this.jdbcServiceManager.getConnection();
  200.        
  201.             return this.serviceSearch.get(this.jdbcProperties,this.log,connection,sqlQueryObject,id,null);
  202.        
  203.         }catch(ServiceException | MultipleResultException | NotImplementedException e){
  204.             this.logError(e); throw e;
  205.         }catch(NotFoundException e){
  206.             this.logDebug(e); throw e;
  207.         }catch(Exception e){
  208.             this.logError(e); throw new ServiceException("Get not completed: "+e.getMessage(),e);
  209.         }finally{
  210.             if(connection!=null){
  211.                 this.jdbcServiceManager.closeConnection(connection);
  212.             }
  213.         }
  214.    
  215.     }

  216.     @Override
  217.     public Transazione get(String id, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws ServiceException, NotFoundException,MultipleResultException, NotImplementedException {
  218.         Connection connection = null;
  219.         try{
  220.            
  221.             // check parameters
  222.             if(id==null){
  223.                 throw this.newServiceExceptionParameterIdIsNull();
  224.             }
  225.             if(idMappingResolutionBehaviour==null){
  226.                 throw this.newServiceExceptionParameterIdMappingResolutionBehaviourIsNull();
  227.             }
  228.            
  229.             // ISQLQueryObject
  230.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  231.             sqlQueryObject.setANDLogicOperator(true);
  232.             // Connection sql
  233.             connection = this.jdbcServiceManager.getConnection();
  234.        
  235.             return this.serviceSearch.get(this.jdbcProperties,this.log,connection,sqlQueryObject,id,idMappingResolutionBehaviour);
  236.        
  237.         }catch(ServiceException | MultipleResultException | NotImplementedException e){
  238.             this.logError(e); throw e;
  239.         }catch(NotFoundException e){
  240.             this.logDebug(e); throw e;
  241.         }catch(Exception e){
  242.             this.logError(e); throw new ServiceException("Get (idMappingResolutionBehaviour) not completed: "+e.getMessage(),e);
  243.         }finally{
  244.             if(connection!=null){
  245.                 this.jdbcServiceManager.closeConnection(connection);
  246.             }
  247.         }
  248.    
  249.     }

  250.     @Override
  251.     public boolean exists(String id) throws MultipleResultException,ServiceException,NotImplementedException {

  252.         Connection connection = null;
  253.         try{
  254.            
  255.             // check parameters
  256.             if(id==null){
  257.                 throw this.newServiceExceptionParameterIdIsNull();
  258.             }

  259.             // ISQLQueryObject
  260.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  261.             sqlQueryObject.setANDLogicOperator(true);
  262.             // Connection sql
  263.             connection = this.jdbcServiceManager.getConnection();

  264.             return this.serviceSearch.exists(this.jdbcProperties,this.log,connection,sqlQueryObject,id);
  265.    
  266.         }catch(MultipleResultException | ServiceException | NotImplementedException e){
  267.             this.logError(e); throw e;
  268.         }catch(Exception e){
  269.             this.logError(e); throw new ServiceException("Exists not completed: "+e.getMessage(),e);
  270.         }finally{
  271.             if(connection!=null){
  272.                 this.jdbcServiceManager.closeConnection(connection);
  273.             }
  274.         }
  275.        
  276.     }
  277.    
  278.     @Override
  279.     public List<String> findAllIds(IPaginatedExpression expression) throws ServiceException, NotImplementedException {

  280.         Connection connection = null;
  281.         try{
  282.            
  283.             // check parameters
  284.             if(expression==null){
  285.                 throw this.newServiceExceptionParameterPaginatedExpressionIsNull();
  286.             }
  287.             if( ! (expression instanceof JDBCPaginatedExpression) ){
  288.                 throw this.newServiceExceptionParameterPaginatedExpressionWrongType(expression);
  289.             }
  290.             JDBCPaginatedExpression jdbcPaginatedExpression = (JDBCPaginatedExpression) expression;
  291.             logJDBCPaginatedExpression(jdbcPaginatedExpression);

  292.             // ISQLQueryObject
  293.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  294.             sqlQueryObject.setANDLogicOperator(true);
  295.             // Connection sql
  296.             connection = this.jdbcServiceManager.getConnection();
  297.            
  298.             return this.serviceSearch.findAllIds(this.jdbcProperties,this.log,connection,sqlQueryObject,jdbcPaginatedExpression,null);
  299.    
  300.         }catch(ServiceException | NotImplementedException e){
  301.             this.logError(e); throw e;
  302.         }catch(Exception e){
  303.             this.logError(e); throw new ServiceException("FindAllIds not completed: "+e.getMessage(),e);
  304.         }finally{
  305.             if(connection!=null){
  306.                 this.jdbcServiceManager.closeConnection(connection);
  307.             }
  308.         }
  309.        
  310.     }
  311.    
  312.     @Override
  313.     public List<String> findAllIds(IPaginatedExpression expression, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws ServiceException, NotImplementedException {

  314.         Connection connection = null;
  315.         try{
  316.            
  317.             // check parameters
  318.             if(idMappingResolutionBehaviour==null){
  319.                 throw this.newServiceExceptionParameterIdMappingResolutionBehaviourIsNull();
  320.             }
  321.             if(expression==null){
  322.                 throw this.newServiceExceptionParameterPaginatedExpressionIsNull();
  323.             }
  324.             if( ! (expression instanceof JDBCPaginatedExpression) ){
  325.                 throw this.newServiceExceptionParameterPaginatedExpressionWrongType(expression);
  326.             }
  327.             JDBCPaginatedExpression jdbcPaginatedExpression = (JDBCPaginatedExpression) expression;
  328.             logJDBCPaginatedExpression(jdbcPaginatedExpression);

  329.             // ISQLQueryObject
  330.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  331.             sqlQueryObject.setANDLogicOperator(true);
  332.             // Connection sql
  333.             connection = this.jdbcServiceManager.getConnection();
  334.            
  335.             return this.serviceSearch.findAllIds(this.jdbcProperties,this.log,connection,sqlQueryObject,jdbcPaginatedExpression,idMappingResolutionBehaviour);
  336.    
  337.         }catch(ServiceException | NotImplementedException e){
  338.             this.logError(e); throw e;
  339.         }catch(Exception e){
  340.             this.logError(e); throw new ServiceException("FindAllIds not completed: "+e.getMessage(),e);
  341.         }finally{
  342.             if(connection!=null){
  343.                 this.jdbcServiceManager.closeConnection(connection);
  344.             }
  345.         }
  346.        
  347.     }

  348.     @Override
  349.     public List<Transazione> findAll(IPaginatedExpression expression) throws ServiceException, NotImplementedException {

  350.         Connection connection = null;
  351.         try{
  352.            
  353.             // check parameters
  354.             if(expression==null){
  355.                 throw this.newServiceExceptionParameterPaginatedExpressionIsNull();
  356.             }
  357.             if( ! (expression instanceof JDBCPaginatedExpression) ){
  358.                 throw this.newServiceExceptionParameterPaginatedExpressionWrongType(expression);
  359.             }
  360.             JDBCPaginatedExpression jdbcPaginatedExpression = (JDBCPaginatedExpression) expression;
  361.             logJDBCPaginatedExpression(jdbcPaginatedExpression);

  362.             // ISQLQueryObject
  363.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  364.             sqlQueryObject.setANDLogicOperator(true);
  365.             // Connection sql
  366.             connection = this.jdbcServiceManager.getConnection();

  367.             return this.serviceSearch.findAll(this.jdbcProperties,this.log,connection,sqlQueryObject,jdbcPaginatedExpression,null);        
  368.    
  369.         }catch(ServiceException | NotImplementedException e){
  370.             this.logError(e); throw e;
  371.         }catch(Exception e){
  372.             this.logError(e); throw new ServiceException("FindAll not completed: "+e.getMessage(),e);
  373.         }finally{
  374.             if(connection!=null){
  375.                 this.jdbcServiceManager.closeConnection(connection);
  376.             }
  377.         }
  378.        
  379.     }
  380.    
  381.     @Override
  382.     public List<Transazione> findAll(IPaginatedExpression expression, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws ServiceException, NotImplementedException {

  383.         Connection connection = null;
  384.         try{
  385.            
  386.             // check parameters
  387.             if(idMappingResolutionBehaviour==null){
  388.                 throw this.newServiceExceptionParameterIdMappingResolutionBehaviourIsNull();
  389.             }
  390.             if(expression==null){
  391.                 throw this.newServiceExceptionParameterPaginatedExpressionIsNull();
  392.             }
  393.             if( ! (expression instanceof JDBCPaginatedExpression) ){
  394.                 throw this.newServiceExceptionParameterPaginatedExpressionWrongType(expression);
  395.             }
  396.             JDBCPaginatedExpression jdbcPaginatedExpression = (JDBCPaginatedExpression) expression;
  397.             logJDBCPaginatedExpression(jdbcPaginatedExpression);

  398.             // ISQLQueryObject
  399.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  400.             sqlQueryObject.setANDLogicOperator(true);
  401.             // Connection sql
  402.             connection = this.jdbcServiceManager.getConnection();

  403.             return this.serviceSearch.findAll(this.jdbcProperties,this.log,connection,sqlQueryObject,jdbcPaginatedExpression,idMappingResolutionBehaviour);        
  404.    
  405.         }catch(ServiceException | NotImplementedException e){
  406.             this.logError(e); throw e;
  407.         }catch(Exception e){
  408.             this.logError(e); throw new ServiceException("FindAll not completed: "+e.getMessage(),e);
  409.         }finally{
  410.             if(connection!=null){
  411.                 this.jdbcServiceManager.closeConnection(connection);
  412.             }
  413.         }
  414.        
  415.     }

  416.     @Override
  417.     public Transazione find(IExpression expression) throws ServiceException, NotFoundException, MultipleResultException, NotImplementedException {

  418.         Connection connection = null;
  419.         try{
  420.            
  421.             // check parameters
  422.             if(expression==null){
  423.                 throw this.newServiceExceptionParameterExpressionIsNull();
  424.             }
  425.             if( ! (expression instanceof JDBCExpression) ){
  426.                 throw this.newServiceExceptionParameterExpressionWrongType(expression);
  427.             }
  428.             JDBCExpression jdbcExpression = (JDBCExpression) expression;
  429.             this.logJDBCExpression(jdbcExpression);

  430.             // ISQLQueryObject
  431.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  432.             sqlQueryObject.setANDLogicOperator(true);
  433.             // Connection sql
  434.             connection = this.jdbcServiceManager.getConnection();

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

  436.         }catch(ServiceException | MultipleResultException | NotImplementedException e){
  437.             this.logError(e); throw e;
  438.         }catch(NotFoundException e){
  439.             this.logDebug(e); throw e;
  440.         }catch(Exception e){
  441.             this.logError(e); throw new ServiceException("Find not completed: "+e.getMessage(),e);
  442.         }finally{
  443.             if(connection!=null){
  444.                 this.jdbcServiceManager.closeConnection(connection);
  445.             }
  446.         }
  447.        
  448.     }
  449.    
  450.     @Override
  451.     public Transazione find(IExpression expression, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws ServiceException, NotFoundException, MultipleResultException, NotImplementedException {

  452.         Connection connection = null;
  453.         try{
  454.            
  455.             // check parameters
  456.             if(idMappingResolutionBehaviour==null){
  457.                 throw this.newServiceExceptionParameterIdMappingResolutionBehaviourIsNull();
  458.             }
  459.             if(expression==null){
  460.                 throw this.newServiceExceptionParameterExpressionIsNull();
  461.             }
  462.             if( ! (expression instanceof JDBCExpression) ){
  463.                 throw this.newServiceExceptionParameterExpressionWrongType(expression);
  464.             }
  465.             JDBCExpression jdbcExpression = (JDBCExpression) expression;
  466.             this.logJDBCExpression(jdbcExpression);

  467.             // ISQLQueryObject
  468.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  469.             sqlQueryObject.setANDLogicOperator(true);
  470.             // Connection sql
  471.             connection = this.jdbcServiceManager.getConnection();

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

  473.         }catch(ServiceException | MultipleResultException | NotImplementedException e){
  474.             this.logError(e); throw e;
  475.         }catch(NotFoundException e){
  476.             this.logDebug(e); throw e;
  477.         }catch(Exception e){
  478.             this.logError(e); throw new ServiceException("Find not completed: "+e.getMessage(),e);
  479.         }finally{
  480.             if(connection!=null){
  481.                 this.jdbcServiceManager.closeConnection(connection);
  482.             }
  483.         }
  484.        
  485.     }

  486.     @Override
  487.     public NonNegativeNumber count(IExpression expression) throws ServiceException, NotImplementedException {

  488.         Connection connection = null;
  489.         try{
  490.            
  491.             // check parameters
  492.             if(expression==null){
  493.                 throw this.newServiceExceptionParameterExpressionIsNull();
  494.             }
  495.             if( ! (expression instanceof JDBCExpression) ){
  496.                 throw this.newServiceExceptionParameterExpressionWrongType(expression);
  497.             }
  498.             JDBCExpression jdbcExpression = (JDBCExpression) expression;
  499.             this.logJDBCExpression(jdbcExpression);
  500.            
  501.             // ISQLQueryObject
  502.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  503.             sqlQueryObject.setANDLogicOperator(true);
  504.             // Connection sql
  505.             connection = this.jdbcServiceManager.getConnection();

  506.             return this.serviceSearch.count(this.jdbcProperties,this.log,connection,sqlQueryObject,jdbcExpression);
  507.    
  508.         }catch(ServiceException | NotImplementedException e){
  509.             this.logError(e); throw e;
  510.         }catch(Exception e){
  511.             this.logError(e); throw new ServiceException("Count not completed: "+e.getMessage(),e);
  512.         }finally{
  513.             if(connection!=null){
  514.                 this.jdbcServiceManager.closeConnection(connection);
  515.             }
  516.         }
  517.        
  518.     }

  519.     @Override
  520.     public InUse inUse(String id) throws ServiceException, NotFoundException,NotImplementedException {

  521.         Connection connection = null;
  522.         try{
  523.            
  524.             // check parameters
  525.             if(id==null){
  526.                 throw this.newServiceExceptionParameterIdIsNull();
  527.             }
  528.            
  529.             // ISQLQueryObject
  530.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  531.             sqlQueryObject.setANDLogicOperator(true);
  532.             // Connection sql
  533.             connection = this.jdbcServiceManager.getConnection();

  534.             return this.serviceSearch.inUse(this.jdbcProperties,this.log,connection,sqlQueryObject,id);
  535.    
  536.         }catch(ServiceException | NotImplementedException e){
  537.             this.logError(e); throw e;
  538.         }catch(NotFoundException e){
  539.             this.logDebug(e); throw e;
  540.         }catch(Exception e){
  541.             this.logError(e); throw new ServiceException("InUse not completed: "+e.getMessage(),e);
  542.         }finally{
  543.             if(connection!=null){
  544.                 this.jdbcServiceManager.closeConnection(connection);
  545.             }
  546.         }
  547.        
  548.     }
  549.    
  550.     @Override
  551.     public List<Object> select(IPaginatedExpression paginatedExpression, IField field) throws ServiceException,NotFoundException,NotImplementedException {
  552.    
  553.         Connection connection = null;
  554.         try{
  555.            
  556.             // check parameters
  557.             if(paginatedExpression==null){
  558.                 throw this.newServiceExceptionParameterPaginatedExpressionIsNullErrorParameterPaginated();
  559.             }
  560.             if( ! (paginatedExpression instanceof JDBCPaginatedExpression) ){
  561.                 throw this.newServiceExceptionParameterPaginatedExpressionWrongTypeErrorParameterPaginated(paginatedExpression);
  562.             }
  563.             JDBCPaginatedExpression jdbcPaginatedExpression = (JDBCPaginatedExpression) paginatedExpression;
  564.             logJDBCPaginatedExpression(jdbcPaginatedExpression);

  565.             // ISQLQueryObject
  566.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  567.             sqlQueryObject.setANDLogicOperator(true);
  568.             // Connection sql
  569.             connection = this.jdbcServiceManager.getConnection();

  570.             return this.serviceSearch.select(this.jdbcProperties,this.log,connection,sqlQueryObject,jdbcPaginatedExpression,field);        
  571.    
  572.         }catch(ServiceException | NotImplementedException e){
  573.             this.logError(e); throw e;
  574.         }catch(NotFoundException e){
  575.             this.logDebug(e); throw e;
  576.         }catch(Exception e){
  577.             this.logError(e); throw new ServiceException("Select 'field' not completed: "+e.getMessage(),e);
  578.         }finally{
  579.             if(connection!=null){
  580.                 this.jdbcServiceManager.closeConnection(connection);
  581.             }
  582.         }
  583.    
  584.     }
  585.    
  586.     @Override
  587.     public List<Object> select(IPaginatedExpression paginatedExpression, boolean distinct, IField field) throws ServiceException,NotFoundException,NotImplementedException {

  588.         Connection connection = null;
  589.         try{
  590.            
  591.             // check parameters
  592.             if(paginatedExpression==null){
  593.                 throw this.newServiceExceptionParameterPaginatedExpressionIsNullErrorParameterPaginated();
  594.             }
  595.             if( ! (paginatedExpression instanceof JDBCPaginatedExpression) ){
  596.                 throw this.newServiceExceptionParameterPaginatedExpressionWrongTypeErrorParameterPaginated(paginatedExpression);
  597.             }
  598.             JDBCPaginatedExpression jdbcPaginatedExpression = (JDBCPaginatedExpression) paginatedExpression;
  599.             logJDBCPaginatedExpression(jdbcPaginatedExpression);

  600.             // ISQLQueryObject
  601.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  602.             sqlQueryObject.setANDLogicOperator(true);
  603.             // Connection sql
  604.             connection = this.jdbcServiceManager.getConnection();

  605.             return this.serviceSearch.select(this.jdbcProperties,this.log,connection,sqlQueryObject,jdbcPaginatedExpression,distinct,field);            
  606.    
  607.         }catch(ServiceException | NotImplementedException e){
  608.             this.logError(e); throw e;
  609.         }catch(NotFoundException e){
  610.             this.logDebug(e); throw e;
  611.         }catch(Exception e){
  612.             this.logError(e); throw new ServiceException("Select 'distinct:"+distinct+"' field not completed: "+e.getMessage(),e);
  613.         }finally{
  614.             if(connection!=null){
  615.                 this.jdbcServiceManager.closeConnection(connection);
  616.             }
  617.         }
  618.        
  619.     }
  620.    
  621.     @Override
  622.     public List<Map<String,Object>> select(IPaginatedExpression paginatedExpression, IField ... field) throws ServiceException,NotFoundException,NotImplementedException {
  623.    
  624.         Connection connection = null;
  625.         try{
  626.            
  627.             // check parameters
  628.             if(paginatedExpression==null){
  629.                 throw this.newServiceExceptionParameterPaginatedExpressionIsNullErrorParameterPaginated();
  630.             }
  631.             if( ! (paginatedExpression instanceof JDBCPaginatedExpression) ){
  632.                 throw this.newServiceExceptionParameterPaginatedExpressionWrongTypeErrorParameterPaginated(paginatedExpression);
  633.             }
  634.             JDBCPaginatedExpression jdbcPaginatedExpression = (JDBCPaginatedExpression) paginatedExpression;
  635.             logJDBCPaginatedExpression(jdbcPaginatedExpression);

  636.             // ISQLQueryObject
  637.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  638.             sqlQueryObject.setANDLogicOperator(true);
  639.             // Connection sql
  640.             connection = this.jdbcServiceManager.getConnection();

  641.             return this.serviceSearch.select(this.jdbcProperties,this.log,connection,sqlQueryObject,jdbcPaginatedExpression,field);        
  642.    
  643.         }catch(ServiceException | NotImplementedException e){
  644.             this.logError(e); throw e;
  645.         }catch(NotFoundException e){
  646.             this.logDebug(e); throw e;
  647.         }catch(Exception e){
  648.             this.logError(e); throw new ServiceException("Select not completed: "+e.getMessage(),e);
  649.         }finally{
  650.             if(connection!=null){
  651.                 this.jdbcServiceManager.closeConnection(connection);
  652.             }
  653.         }
  654.    
  655.     }
  656.     @Override
  657.     public List<Map<String,Object>> select(IPaginatedExpression paginatedExpression, boolean distinct, IField ... field) throws ServiceException,NotFoundException,NotImplementedException {

  658.         Connection connection = null;
  659.         try{
  660.            
  661.             // check parameters
  662.             if(paginatedExpression==null){
  663.                 throw this.newServiceExceptionParameterPaginatedExpressionIsNullErrorParameterPaginated();
  664.             }
  665.             if( ! (paginatedExpression instanceof JDBCPaginatedExpression) ){
  666.                 throw this.newServiceExceptionParameterPaginatedExpressionWrongTypeErrorParameterPaginated(paginatedExpression);
  667.             }
  668.             JDBCPaginatedExpression jdbcPaginatedExpression = (JDBCPaginatedExpression) paginatedExpression;
  669.             logJDBCPaginatedExpression(jdbcPaginatedExpression);

  670.             // ISQLQueryObject
  671.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  672.             sqlQueryObject.setANDLogicOperator(true);
  673.             // Connection sql
  674.             connection = this.jdbcServiceManager.getConnection();

  675.             return this.serviceSearch.select(this.jdbcProperties,this.log,connection,sqlQueryObject,jdbcPaginatedExpression,distinct,field);            
  676.    
  677.         }catch(ServiceException | NotImplementedException e){
  678.             this.logError(e); throw e;
  679.         }catch(NotFoundException e){
  680.             this.logDebug(e); throw e;
  681.         }catch(Exception e){
  682.             this.logError(e); throw new ServiceException("Select distinct:"+distinct+" not completed: "+e.getMessage(),e);
  683.         }finally{
  684.             if(connection!=null){
  685.                 this.jdbcServiceManager.closeConnection(connection);
  686.             }
  687.         }
  688.        
  689.     }
  690.    
  691.     @Override
  692.     public Object aggregate(IExpression expression, FunctionField functionField) throws ServiceException,NotFoundException,NotImplementedException {

  693.         Connection connection = null;
  694.         try{
  695.            
  696.             // check parameters
  697.             if(expression==null){
  698.                 throw this.newServiceExceptionParameterExpressionIsNull();
  699.             }
  700.             if( ! (expression instanceof JDBCExpression) ){
  701.                 throw this.newServiceExceptionParameterExpressionWrongType(expression);
  702.             }
  703.             JDBCExpression jdbcExpression = (JDBCExpression) expression;
  704.             this.logJDBCExpression(jdbcExpression);

  705.             // ISQLQueryObject
  706.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  707.             sqlQueryObject.setANDLogicOperator(true);
  708.             // Connection sql
  709.             connection = this.jdbcServiceManager.getConnection();

  710.             return this.serviceSearch.aggregate(this.jdbcProperties,this.log,connection,sqlQueryObject,jdbcExpression,functionField);          
  711.    
  712.         }catch(ServiceException | NotImplementedException e){
  713.             this.logError(e); throw e;
  714.         }catch(NotFoundException e){
  715.             this.logDebug(e); throw e;
  716.         }catch(Exception e){
  717.             this.logError(e); throw new ServiceException("Aggregate not completed: "+e.getMessage(),e);
  718.         }finally{
  719.             if(connection!=null){
  720.                 this.jdbcServiceManager.closeConnection(connection);
  721.             }
  722.         }
  723.        
  724.     }
  725.    
  726.     @Override
  727.     public Map<String,Object> aggregate(IExpression expression, FunctionField ... functionField) throws ServiceException,NotFoundException,NotImplementedException {

  728.         Connection connection = null;
  729.         try{
  730.            
  731.             // check parameters
  732.             if(expression==null){
  733.                 throw this.newServiceExceptionParameterExpressionIsNull();
  734.             }
  735.             if( ! (expression instanceof JDBCExpression) ){
  736.                 throw this.newServiceExceptionParameterExpressionWrongType(expression);
  737.             }
  738.             JDBCExpression jdbcExpression = (JDBCExpression) expression;
  739.             this.logJDBCExpression(jdbcExpression);

  740.             // ISQLQueryObject
  741.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  742.             sqlQueryObject.setANDLogicOperator(true);
  743.             // Connection sql
  744.             connection = this.jdbcServiceManager.getConnection();

  745.             return this.serviceSearch.aggregate(this.jdbcProperties,this.log,connection,sqlQueryObject,jdbcExpression,functionField);          
  746.    
  747.         }catch(ServiceException | NotImplementedException e){
  748.             this.logError(e); throw e;
  749.         }catch(NotFoundException e){
  750.             this.logDebug(e); throw e;
  751.         }catch(Exception e){
  752.             this.logError(e); throw new ServiceException("Aggregate not completed: "+e.getMessage(),e);
  753.         }finally{
  754.             if(connection!=null){
  755.                 this.jdbcServiceManager.closeConnection(connection);
  756.             }
  757.         }
  758.        
  759.     }
  760.    
  761.     @Override
  762.     public List<Map<String,Object>> groupBy(IExpression expression, FunctionField ... functionField) throws ServiceException,NotFoundException,NotImplementedException {

  763.         Connection connection = null;
  764.         try{
  765.            
  766.             // check parameters
  767.             if(expression==null){
  768.                 throw this.newServiceExceptionParameterExpressionIsNull();
  769.             }
  770.             if( ! (expression instanceof JDBCExpression) ){
  771.                 throw this.newServiceExceptionParameterExpressionWrongType(expression);
  772.             }
  773.             JDBCExpression jdbcExpression = (JDBCExpression) expression;
  774.             this.logJDBCExpression(jdbcExpression);

  775.             // ISQLQueryObject
  776.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  777.             sqlQueryObject.setANDLogicOperator(true);
  778.             // Connection sql
  779.             connection = this.jdbcServiceManager.getConnection();

  780.             return this.serviceSearch.groupBy(this.jdbcProperties,this.log,connection,sqlQueryObject,jdbcExpression,functionField);        
  781.    
  782.         }catch(ServiceException | NotImplementedException e){
  783.             this.logError(e); throw e;
  784.         }catch(NotFoundException e){
  785.             this.logDebug(e); throw e;
  786.         }catch(Exception e){
  787.             this.logError(e); throw new ServiceException("GroupBy not completed: "+e.getMessage(),e);
  788.         }finally{
  789.             if(connection!=null){
  790.                 this.jdbcServiceManager.closeConnection(connection);
  791.             }
  792.         }
  793.        
  794.     }
  795.    
  796.     @Override
  797.     public List<Map<String,Object>> groupBy(IPaginatedExpression paginatedExpression, FunctionField ... functionField) throws ServiceException,NotFoundException,NotImplementedException {

  798.         Connection connection = null;
  799.         try{
  800.            
  801.             // check parameters
  802.             if(paginatedExpression==null){
  803.                 throw this.newServiceExceptionParameterPaginatedExpressionIsNullErrorParameterPaginated();
  804.             }
  805.             if( ! (paginatedExpression instanceof JDBCPaginatedExpression) ){
  806.                 throw this.newServiceExceptionParameterPaginatedExpressionWrongTypeErrorParameterPaginated(paginatedExpression);
  807.             }
  808.             JDBCPaginatedExpression jdbcPaginatedExpression = (JDBCPaginatedExpression) paginatedExpression;
  809.             logJDBCPaginatedExpression(jdbcPaginatedExpression);

  810.             // ISQLQueryObject
  811.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  812.             sqlQueryObject.setANDLogicOperator(true);
  813.             // Connection sql
  814.             connection = this.jdbcServiceManager.getConnection();

  815.             return this.serviceSearch.groupBy(this.jdbcProperties,this.log,connection,sqlQueryObject,jdbcPaginatedExpression,functionField);            
  816.    
  817.         }catch(ServiceException | NotImplementedException e){
  818.             this.logError(e); throw e;
  819.         }catch(NotFoundException e){
  820.             this.logDebug(e); throw e;
  821.         }catch(Exception e){
  822.             this.logError(e); throw new ServiceException("GroupBy not completed: "+e.getMessage(),e);
  823.         }finally{
  824.             if(connection!=null){
  825.                 this.jdbcServiceManager.closeConnection(connection);
  826.             }
  827.         }
  828.        
  829.     }
  830.    
  831.     @Override
  832.     public List<Map<String,Object>> union(Union union, UnionExpression ... unionExpression) throws ServiceException,NotFoundException,NotImplementedException {

  833.         Connection connection = null;
  834.         try{
  835.            
  836.             // check parameters
  837.             if(unionExpression==null){
  838.                 throw this.newServiceExceptionParameterUnionExpressionIsNull();
  839.             }
  840.            
  841.             // ISQLQueryObject
  842.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  843.             sqlQueryObject.setANDLogicOperator(true);
  844.             // Connection sql
  845.             connection = this.jdbcServiceManager.getConnection();

  846.             return this.serviceSearch.union(this.jdbcProperties,this.log,connection,sqlQueryObject,union,unionExpression);          
  847.    
  848.         }catch(ServiceException | NotImplementedException e){
  849.             this.logError(e); throw e;
  850.         }catch(NotFoundException e){
  851.             this.logDebug(e); throw e;
  852.         }catch(Exception e){
  853.             this.logError(e); throw new ServiceException("Union not completed: "+e.getMessage(),e);
  854.         }finally{
  855.             if(connection!=null){
  856.                 this.jdbcServiceManager.closeConnection(connection);
  857.             }
  858.         }
  859.        
  860.     }
  861.    
  862.     @Override
  863.     public NonNegativeNumber unionCount(Union union, UnionExpression ... unionExpression) throws ServiceException,NotFoundException,NotImplementedException {

  864.         Connection connection = null;
  865.         try{
  866.            
  867.             // check parameters
  868.             if(unionExpression==null){
  869.                 throw this.newServiceExceptionParameterUnionExpressionIsNull();
  870.             }
  871.            
  872.             // ISQLQueryObject
  873.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  874.             sqlQueryObject.setANDLogicOperator(true);
  875.             // Connection sql
  876.             connection = this.jdbcServiceManager.getConnection();

  877.             return this.serviceSearch.unionCount(this.jdbcProperties,this.log,connection,sqlQueryObject,union,unionExpression);        
  878.    
  879.         }catch(ServiceException | NotImplementedException e){
  880.             this.logError(e); throw e;
  881.         }catch(NotFoundException e){
  882.             this.logDebug(e); throw e;
  883.         }catch(Exception e){
  884.             this.logError(e); throw new ServiceException("UnionCount not completed: "+e.getMessage(),e);
  885.         }finally{
  886.             if(connection!=null){
  887.                 this.jdbcServiceManager.closeConnection(connection);
  888.             }
  889.         }
  890.        
  891.     }

  892.     @Override
  893.     public IExpression newExpression() throws ServiceException,NotImplementedException {

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

  895.     }

  896.     @Override
  897.     public IPaginatedExpression newPaginatedExpression() throws ServiceException, NotImplementedException {

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

  899.     }
  900.    
  901.     @Override
  902.     public IExpression toExpression(IPaginatedExpression paginatedExpression) throws ServiceException,NotImplementedException {

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

  904.     }

  905.     @Override
  906.     public IPaginatedExpression toPaginatedExpression(IExpression expression) throws ServiceException, NotImplementedException {

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

  908.     }
  909.    

  910.     public void disableSelectForUpdate() throws ServiceException,NotImplementedException {
  911.         this.jdbcSqlObjectFactory.setSelectForUpdate(false);
  912.     }

  913.     public void enableSelectForUpdate() throws ServiceException,NotImplementedException {
  914.         this.jdbcSqlObjectFactory.setSelectForUpdate(true);
  915.     }
  916.    
  917.    
  918.     @Override
  919.     public List<List<Object>> nativeQuery(String sql,List<Class<?>> returnClassTypes,Object ... param) throws ServiceException,NotFoundException,NotImplementedException{
  920.    
  921.         Connection connection = null;
  922.         try{
  923.            
  924.             // check parameters
  925.             if(returnClassTypes==null || returnClassTypes.isEmpty()){
  926.                 throw new ServiceException("Parameter 'returnClassTypes' is less equals 0");
  927.             }
  928.            
  929.             // ISQLQueryObject
  930.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  931.             sqlQueryObject.setANDLogicOperator(true);
  932.             // Connection sql
  933.             connection = this.jdbcServiceManager.getConnection();

  934.             return this.serviceSearch.nativeQuery(this.jdbcProperties,this.log,connection,sqlQueryObject,sql,returnClassTypes,param);      
  935.    
  936.         }catch(ServiceException | NotImplementedException e){
  937.             this.logError(e); throw e;
  938.         }catch(NotFoundException e){
  939.             this.logDebug(e); throw e;
  940.         }catch(Exception e){
  941.             this.logError(e); throw new ServiceException("nativeQuery not completed: "+e.getMessage(),e);
  942.         }finally{
  943.             if(connection!=null){
  944.                 this.jdbcServiceManager.closeConnection(connection);
  945.             }
  946.         }
  947.    
  948.     }
  949.    
  950. }