JDBCConfigurazioneFiltroService.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */
  20. package org.openspcoop2.core.plugins.dao.jdbc;

  21. import org.openspcoop2.generic_project.dao.jdbc.IJDBCServiceCRUDWithId;
  22. import org.openspcoop2.core.plugins.IdConfigurazioneFiltro;

  23. import org.openspcoop2.generic_project.beans.NonNegativeNumber;
  24. import org.openspcoop2.generic_project.beans.UpdateField;
  25. import org.openspcoop2.generic_project.beans.UpdateModel;
  26. import org.openspcoop2.generic_project.dao.jdbc.JDBCProperties;
  27. import org.openspcoop2.generic_project.exception.NotFoundException;
  28. import org.openspcoop2.generic_project.exception.NotImplementedException;
  29. import org.openspcoop2.generic_project.exception.ServiceException;
  30. import org.openspcoop2.generic_project.exception.ValidationException;
  31. import org.openspcoop2.generic_project.expression.IExpression;
  32. import org.openspcoop2.generic_project.dao.jdbc.JDBCExpression;

  33. import org.openspcoop2.core.plugins.ConfigurazioneFiltro;
  34. import org.openspcoop2.core.plugins.dao.IDBConfigurazioneFiltroService;
  35. import org.openspcoop2.core.plugins.utils.ProjectInfo;

  36. import java.sql.Connection;

  37. import org.openspcoop2.utils.sql.ISQLQueryObject;

  38. /**    
  39.  * Service can be used to search for and manage the backend objects of type {@link org.openspcoop2.core.plugins.ConfigurazioneFiltro}
  40.  *
  41.  * @author Poli Andrea (poli@link.it)
  42.  * @author $Author$
  43.  * @version $Rev$, $Date$
  44.  */

  45. public class JDBCConfigurazioneFiltroService extends JDBCConfigurazioneFiltroServiceSearch  implements IDBConfigurazioneFiltroService {


  46.     private IJDBCServiceCRUDWithId<ConfigurazioneFiltro, IdConfigurazioneFiltro, JDBCServiceManager> serviceCRUD = null;
  47.     public JDBCConfigurazioneFiltroService(JDBCServiceManager jdbcServiceManager) throws ServiceException {
  48.         super(jdbcServiceManager);
  49.         String msgInit = JDBCConfigurazioneFiltroService.class.getName()+ " initialized";
  50.         this.log.debug(msgInit);
  51.         this.serviceCRUD = JDBCProperties.getInstance(org.openspcoop2.core.plugins.dao.jdbc.JDBCServiceManager.class.getPackage(),ProjectInfo.getInstance()).getServiceCRUD("configurazioneFiltro");
  52.         this.serviceCRUD.setServiceManager(new JDBCLimitedServiceManager(this.jdbcServiceManager));
  53.     }

  54.     private static final String PARAMETER_TYPE_PREFIX = "Parameter (type:";
  55.     private ServiceException newServiceExceptionParameterIsNull(){
  56.         return new ServiceException(PARAMETER_TYPE_PREFIX+ConfigurazioneFiltro.class.getName()+") 'configurazioneFiltro' is null");
  57.     }
  58.     private ServiceException newServiceExceptionParameterIsLessEqualsZero(){
  59.         return new ServiceException(PARAMETER_TYPE_PREFIX+long.class.getName()+") 'tableId' is less equals 0");
  60.     }
  61.     private ServiceException newServiceExceptionParameterUpdateFieldsIsNull(){
  62.         return new ServiceException(PARAMETER_TYPE_PREFIX+UpdateField.class.getName()+") 'updateFields' is null");
  63.     }
  64.     private ServiceException newServiceExceptionParameterOldIdIsNull(){
  65.         return new ServiceException(PARAMETER_TYPE_PREFIX+IdConfigurazioneFiltro.class.getName()+") 'oldId' is null");
  66.     }
  67.     private ServiceException newServiceExceptionParameterConditionIsNull(){
  68.         return new ServiceException(PARAMETER_TYPE_PREFIX+IExpression.class.getName()+") 'condition' is null");
  69.     }
  70.     private ServiceException newServiceExceptionParameterUpdateModelsIsNull(){
  71.         return new ServiceException(PARAMETER_TYPE_PREFIX+UpdateModel.class.getName()+") 'updateModels' is null");
  72.     }
  73.    
  74.     private ServiceException newServiceExceptionUpdateFieldsNotCompleted(Exception e){
  75.         return new ServiceException("UpdateFields not completed: "+e.getMessage(),e);
  76.     }
  77.    
  78.    
  79.     private void releaseResources(boolean rollback, Connection connection, boolean oldValueAutoCommit) throws ServiceException {
  80.         if(this.jdbcProperties.isAutomaticTransactionManagement()){
  81.             manageTransaction(rollback, connection);
  82.             try{
  83.                 if(connection!=null)
  84.                     connection.setAutoCommit(oldValueAutoCommit);
  85.             }catch(Exception eIgnore){
  86.                 // ignore
  87.             }
  88.         }
  89.         if(connection!=null){
  90.             this.jdbcServiceManager.closeConnection(connection);
  91.         }
  92.     }
  93.     private void manageTransaction(boolean rollback, Connection connection) {
  94.         if(rollback){
  95.             try{
  96.                 if(connection!=null)
  97.                     connection.rollback();
  98.             }catch(Exception eIgnore){
  99.                 // ignore
  100.             }
  101.         }else{
  102.             try{
  103.                 if(connection!=null)
  104.                     connection.commit();
  105.             }catch(Exception eIgnore){
  106.                 // ignore
  107.             }
  108.         }
  109.     }
  110.    
  111.    
  112.    
  113.     @Override
  114.     public void create(ConfigurazioneFiltro configurazioneFiltro) throws ServiceException, NotImplementedException {
  115.         try{
  116.             this.create(configurazioneFiltro, false, null);
  117.         }catch(ValidationException vE){
  118.             // not possible
  119.             throw new ServiceException(vE.getMessage(), vE);
  120.         }
  121.     }
  122.    
  123.     @Override
  124.     public void create(ConfigurazioneFiltro configurazioneFiltro, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws ServiceException, NotImplementedException {
  125.         try{
  126.             this.create(configurazioneFiltro, false, idMappingResolutionBehaviour);
  127.         }catch(ValidationException vE){
  128.             // not possible
  129.             throw new ServiceException(vE.getMessage(), vE);
  130.         }
  131.     }
  132.    
  133.     @Override
  134.     public void create(ConfigurazioneFiltro configurazioneFiltro, boolean validate) throws ServiceException, NotImplementedException, ValidationException {
  135.         this.create(configurazioneFiltro, validate, null);
  136.     }
  137.    
  138.     @Override
  139.     public void create(ConfigurazioneFiltro configurazioneFiltro, boolean validate, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws ServiceException, NotImplementedException, ValidationException {
  140.        
  141.         Connection connection = null;
  142.         boolean oldValueAutoCommit = false;
  143.         boolean rollback = false;
  144.         try{
  145.            
  146.             // check parameters
  147.             if(configurazioneFiltro==null){
  148.                 throw this.newServiceExceptionParameterIsNull();
  149.             }
  150.            
  151.             // validate
  152.             if(validate){
  153.                 this.validate(configurazioneFiltro);
  154.             }

  155.             // ISQLQueryObject
  156.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  157.             sqlQueryObject.setANDLogicOperator(true);
  158.             // Connection sql
  159.             connection = this.jdbcServiceManager.getConnection();
  160.    
  161.             // transaction
  162.             if(this.jdbcProperties.isAutomaticTransactionManagement()){
  163.                 oldValueAutoCommit = connection.getAutoCommit();
  164.                 connection.setAutoCommit(false);
  165.             }
  166.        
  167.             this.serviceCRUD.create(this.jdbcProperties,this.log,connection,sqlQueryObject,configurazioneFiltro,idMappingResolutionBehaviour);          

  168.         }catch(ServiceException | NotImplementedException | ValidationException e){
  169.             rollback = true;
  170.             this.logError(e); throw e;
  171.         }catch(Exception e){
  172.             rollback = true;
  173.             this.logError(e); throw new ServiceException("Create not completed: "+e.getMessage(),e);
  174.         }finally{
  175.             this.releaseResources(rollback, connection, oldValueAutoCommit);
  176.         }

  177.     }

  178.     @Override
  179.     public void update(IdConfigurazioneFiltro oldId, ConfigurazioneFiltro configurazioneFiltro) throws ServiceException, NotFoundException, NotImplementedException {
  180.         try{
  181.             this.update(oldId, configurazioneFiltro, false, null);
  182.         }catch(ValidationException vE){
  183.             // not possible
  184.             throw new ServiceException(vE.getMessage(), vE);
  185.         }
  186.     }
  187.    
  188.     @Override
  189.     public void update(IdConfigurazioneFiltro oldId, ConfigurazioneFiltro configurazioneFiltro, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws ServiceException, NotFoundException, NotImplementedException {
  190.         try{
  191.             this.update(oldId, configurazioneFiltro, false, idMappingResolutionBehaviour);
  192.         }catch(ValidationException vE){
  193.             // not possible
  194.             throw new ServiceException(vE.getMessage(), vE);
  195.         }
  196.     }
  197.    
  198.     @Override
  199.     public void update(IdConfigurazioneFiltro oldId, ConfigurazioneFiltro configurazioneFiltro, boolean validate) throws ServiceException, NotFoundException, NotImplementedException, ValidationException {
  200.         this.update(oldId, configurazioneFiltro, validate, null);
  201.     }
  202.        
  203.     @Override
  204.     public void update(IdConfigurazioneFiltro oldId, ConfigurazioneFiltro configurazioneFiltro, boolean validate, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws ServiceException, NotFoundException, NotImplementedException, ValidationException {
  205.    
  206.         Connection connection = null;
  207.         boolean oldValueAutoCommit = false;
  208.         boolean rollback = false;
  209.         try{
  210.            
  211.             // check parameters
  212.             if(configurazioneFiltro==null){
  213.                 throw this.newServiceExceptionParameterIsNull();
  214.             }
  215.             if(oldId==null){
  216.                 throw this.newServiceExceptionParameterOldIdIsNull();
  217.             }

  218.             // validate
  219.             if(validate){
  220.                 this.validate(configurazioneFiltro);
  221.             }

  222.             // ISQLQueryObject
  223.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  224.             sqlQueryObject.setANDLogicOperator(true);
  225.             // Connection sql
  226.             connection = this.jdbcServiceManager.getConnection();
  227.        
  228.             // transaction
  229.             if(this.jdbcProperties.isAutomaticTransactionManagement()){
  230.                 oldValueAutoCommit = connection.getAutoCommit();
  231.                 connection.setAutoCommit(false);
  232.             }

  233.             this.serviceCRUD.update(this.jdbcProperties,this.log,connection,sqlQueryObject,oldId,configurazioneFiltro,idMappingResolutionBehaviour);
  234.            
  235.         }catch(ServiceException | NotImplementedException | ValidationException e){
  236.             rollback = true;
  237.             this.logError(e); throw e;
  238.         }catch(NotFoundException e){
  239.             rollback = true;
  240.             this.logDebug(e); throw e;
  241.         }catch(Exception e){
  242.             rollback = true;
  243.             this.logError(e); throw new ServiceException("Update not completed: "+e.getMessage(),e);
  244.         }finally{
  245.             this.releaseResources(rollback, connection, oldValueAutoCommit);
  246.         }

  247.     }
  248.    
  249.     @Override
  250.     public void update(long tableId, ConfigurazioneFiltro configurazioneFiltro) throws ServiceException, NotFoundException, NotImplementedException {
  251.         try{
  252.             this.update(tableId, configurazioneFiltro, false, null);
  253.         }catch(ValidationException vE){
  254.             // not possible
  255.             throw new ServiceException(vE.getMessage(), vE);
  256.         }
  257.     }
  258.    
  259.     @Override
  260.     public void update(long tableId, ConfigurazioneFiltro configurazioneFiltro, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws ServiceException, NotFoundException, NotImplementedException {
  261.         try{
  262.             this.update(tableId, configurazioneFiltro, false, idMappingResolutionBehaviour);
  263.         }catch(ValidationException vE){
  264.             // not possible
  265.             throw new ServiceException(vE.getMessage(), vE);
  266.         }
  267.     }
  268.    
  269.     @Override
  270.     public void update(long tableId, ConfigurazioneFiltro configurazioneFiltro, boolean validate) throws ServiceException, NotFoundException, NotImplementedException, ValidationException {
  271.         this.update(tableId, configurazioneFiltro, validate, null);
  272.     }
  273.        
  274.     @Override
  275.     public void update(long tableId, ConfigurazioneFiltro configurazioneFiltro, boolean validate, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws ServiceException, NotFoundException, NotImplementedException, ValidationException {
  276.    
  277.         Connection connection = null;
  278.         boolean oldValueAutoCommit = false;
  279.         boolean rollback = false;
  280.         try{
  281.            
  282.             // check parameters
  283.             if(configurazioneFiltro==null){
  284.                 throw this.newServiceExceptionParameterIsNull();
  285.             }
  286.             if(tableId<=0){
  287.                 throw this.newServiceExceptionParameterIsLessEqualsZero();
  288.             }

  289.             // validate
  290.             if(validate){
  291.                 this.validate(configurazioneFiltro);
  292.             }

  293.             // ISQLQueryObject
  294.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  295.             sqlQueryObject.setANDLogicOperator(true);
  296.             // Connection sql
  297.             connection = this.jdbcServiceManager.getConnection();
  298.        
  299.             // transaction
  300.             if(this.jdbcProperties.isAutomaticTransactionManagement()){
  301.                 oldValueAutoCommit = connection.getAutoCommit();
  302.                 connection.setAutoCommit(false);
  303.             }

  304.             this.serviceCRUD.update(this.jdbcProperties,this.log,connection,sqlQueryObject,tableId,configurazioneFiltro,idMappingResolutionBehaviour);
  305.            
  306.         }catch(ServiceException | NotImplementedException | ValidationException e){
  307.             rollback = true;
  308.             this.logError(e); throw e;
  309.         }catch(NotFoundException e){
  310.             rollback = true;
  311.             this.logDebug(e); throw e;
  312.         }catch(Exception e){
  313.             rollback = true;
  314.             this.logError(e); throw new ServiceException("Update not completed: "+e.getMessage(),e);
  315.         }finally{
  316.             this.releaseResources(rollback, connection, oldValueAutoCommit);
  317.         }

  318.     }
  319.    
  320.     @Override
  321.     public void updateFields(IdConfigurazioneFiltro id, UpdateField ... updateFields) throws ServiceException, NotFoundException, NotImplementedException {
  322.    
  323.         Connection connection = null;
  324.         boolean oldValueAutoCommit = false;
  325.         boolean rollback = false;
  326.         try{
  327.            
  328.             // check parameters
  329.             if(id==null){
  330.                 throw this.newServiceExceptionParameterIdIsNull();
  331.             }
  332.             if(updateFields==null){
  333.                 throw this.newServiceExceptionParameterUpdateFieldsIsNull();
  334.             }

  335.             // ISQLQueryObject
  336.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  337.             sqlQueryObject.setANDLogicOperator(true);
  338.             // Connection sql
  339.             connection = this.jdbcServiceManager.getConnection();
  340.        
  341.             // transaction
  342.             if(this.jdbcProperties.isAutomaticTransactionManagement()){
  343.                 oldValueAutoCommit = connection.getAutoCommit();
  344.                 connection.setAutoCommit(false);
  345.             }

  346.             this.serviceCRUD.updateFields(this.jdbcProperties,this.log,connection,sqlQueryObject,id,updateFields);
  347.            
  348.         }catch(ServiceException | NotImplementedException e){
  349.             rollback = true;
  350.             this.logError(e); throw e;
  351.         }catch(NotFoundException e){
  352.             rollback = true;
  353.             this.logDebug(e); throw e;
  354.         }catch(Exception e){
  355.             rollback = true;
  356.             this.logError(e); throw this.newServiceExceptionUpdateFieldsNotCompleted(e);
  357.         }finally{
  358.             this.releaseResources(rollback, connection, oldValueAutoCommit);
  359.         }

  360.     }
  361.    
  362.     @Override
  363.     public void updateFields(IdConfigurazioneFiltro id, IExpression condition, UpdateField ... updateFields) throws ServiceException, NotFoundException, NotImplementedException {
  364.    
  365.         Connection connection = null;
  366.         boolean oldValueAutoCommit = false;
  367.         boolean rollback = false;
  368.         try{
  369.            
  370.             // check parameters
  371.             if(id==null){
  372.                 throw this.newServiceExceptionParameterIdIsNull();
  373.             }
  374.             if(condition==null){
  375.                 throw this.newServiceExceptionParameterConditionIsNull();
  376.             }
  377.             if(updateFields==null){
  378.                 throw this.newServiceExceptionParameterUpdateFieldsIsNull();
  379.             }

  380.             // ISQLQueryObject
  381.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  382.             sqlQueryObject.setANDLogicOperator(true);
  383.             // Connection sql
  384.             connection = this.jdbcServiceManager.getConnection();
  385.        
  386.             // transaction
  387.             if(this.jdbcProperties.isAutomaticTransactionManagement()){
  388.                 oldValueAutoCommit = connection.getAutoCommit();
  389.                 connection.setAutoCommit(false);
  390.             }

  391.             this.serviceCRUD.updateFields(this.jdbcProperties,this.log,connection,sqlQueryObject,id,condition,updateFields);
  392.            
  393.         }catch(ServiceException | NotImplementedException e){
  394.             rollback = true;
  395.             this.logError(e); throw e;
  396.         }catch(NotFoundException e){
  397.             rollback = true;
  398.             this.logDebug(e); throw e;
  399.         }catch(Exception e){
  400.             rollback = true;
  401.             this.logError(e); throw this.newServiceExceptionUpdateFieldsNotCompleted(e);
  402.         }finally{
  403.             this.releaseResources(rollback, connection, oldValueAutoCommit);
  404.         }

  405.     }

  406.     @Override
  407.     public void updateFields(IdConfigurazioneFiltro id, UpdateModel ... updateModels) throws ServiceException, NotFoundException, NotImplementedException {
  408.    
  409.         Connection connection = null;
  410.         boolean oldValueAutoCommit = false;
  411.         boolean rollback = false;
  412.         try{
  413.            
  414.             // check parameters
  415.             if(id==null){
  416.                 throw this.newServiceExceptionParameterIdIsNull();
  417.             }
  418.             if(updateModels==null){
  419.                 throw this.newServiceExceptionParameterUpdateModelsIsNull();
  420.             }

  421.             // ISQLQueryObject
  422.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  423.             sqlQueryObject.setANDLogicOperator(true);
  424.             // Connection sql
  425.             connection = this.jdbcServiceManager.getConnection();
  426.        
  427.             // transaction
  428.             if(this.jdbcProperties.isAutomaticTransactionManagement()){
  429.                 oldValueAutoCommit = connection.getAutoCommit();
  430.                 connection.setAutoCommit(false);
  431.             }

  432.             this.serviceCRUD.updateFields(this.jdbcProperties,this.log,connection,sqlQueryObject,id,updateModels);
  433.            
  434.         }catch(ServiceException | NotImplementedException e){
  435.             rollback = true;
  436.             this.logError(e); throw e;
  437.         }catch(NotFoundException e){
  438.             rollback = true;
  439.             this.logDebug(e); throw e;
  440.         }catch(Exception e){
  441.             rollback = true;
  442.             this.logError(e); throw this.newServiceExceptionUpdateFieldsNotCompleted(e);
  443.         }finally{
  444.             this.releaseResources(rollback, connection, oldValueAutoCommit);
  445.         }

  446.     }

  447.     @Override
  448.     public void updateFields(long tableId, UpdateField ... updateFields) throws ServiceException, NotFoundException, NotImplementedException {
  449.    
  450.         Connection connection = null;
  451.         boolean oldValueAutoCommit = false;
  452.         boolean rollback = false;
  453.         try{
  454.            
  455.             // check parameters
  456.             if(tableId<=0){
  457.                 throw this.newServiceExceptionParameterIsLessEqualsZero();
  458.             }
  459.             if(updateFields==null){
  460.                 throw this.newServiceExceptionParameterUpdateFieldsIsNull();
  461.             }

  462.             // ISQLQueryObject
  463.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  464.             sqlQueryObject.setANDLogicOperator(true);
  465.             // Connection sql
  466.             connection = this.jdbcServiceManager.getConnection();
  467.        
  468.             // transaction
  469.             if(this.jdbcProperties.isAutomaticTransactionManagement()){
  470.                 oldValueAutoCommit = connection.getAutoCommit();
  471.                 connection.setAutoCommit(false);
  472.             }

  473.             this.serviceCRUD.updateFields(this.jdbcProperties,this.log,connection,sqlQueryObject,tableId,updateFields);
  474.            
  475.         }catch(ServiceException | NotImplementedException e){
  476.             rollback = true;
  477.             this.logError(e); throw e;
  478.         }catch(NotFoundException e){
  479.             rollback = true;
  480.             this.logDebug(e); throw e;
  481.         }catch(Exception e){
  482.             rollback = true;
  483.             this.logError(e); throw this.newServiceExceptionUpdateFieldsNotCompleted(e);
  484.         }finally{
  485.             this.releaseResources(rollback, connection, oldValueAutoCommit);
  486.         }

  487.     }
  488.    
  489.     @Override
  490.     public void updateFields(long tableId, IExpression condition, UpdateField ... updateFields) throws ServiceException, NotFoundException, NotImplementedException {
  491.    
  492.         Connection connection = null;
  493.         boolean oldValueAutoCommit = false;
  494.         boolean rollback = false;
  495.         try{
  496.            
  497.             // check parameters
  498.             if(tableId<=0){
  499.                 throw this.newServiceExceptionParameterIsLessEqualsZero();
  500.             }
  501.             if(condition==null){
  502.                 throw this.newServiceExceptionParameterConditionIsNull();
  503.             }
  504.             if(updateFields==null){
  505.                 throw this.newServiceExceptionParameterUpdateFieldsIsNull();
  506.             }

  507.             // ISQLQueryObject
  508.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  509.             sqlQueryObject.setANDLogicOperator(true);
  510.             // Connection sql
  511.             connection = this.jdbcServiceManager.getConnection();
  512.        
  513.             // transaction
  514.             if(this.jdbcProperties.isAutomaticTransactionManagement()){
  515.                 oldValueAutoCommit = connection.getAutoCommit();
  516.                 connection.setAutoCommit(false);
  517.             }

  518.             this.serviceCRUD.updateFields(this.jdbcProperties,this.log,connection,sqlQueryObject,tableId,condition,updateFields);
  519.            
  520.         }catch(ServiceException | NotImplementedException e){
  521.             rollback = true;
  522.             this.logError(e); throw e;
  523.         }catch(NotFoundException e){
  524.             rollback = true;
  525.             this.logDebug(e); throw e;
  526.         }catch(Exception e){
  527.             rollback = true;
  528.             this.logError(e); throw this.newServiceExceptionUpdateFieldsNotCompleted(e);
  529.         }finally{
  530.             this.releaseResources(rollback, connection, oldValueAutoCommit);
  531.         }

  532.     }

  533.     @Override
  534.     public void updateFields(long tableId, UpdateModel ... updateModels) throws ServiceException, NotFoundException, NotImplementedException {
  535.    
  536.         Connection connection = null;
  537.         boolean oldValueAutoCommit = false;
  538.         boolean rollback = false;
  539.         try{
  540.            
  541.             // check parameters
  542.             if(tableId<=0){
  543.                 throw this.newServiceExceptionParameterIsLessEqualsZero();
  544.             }
  545.             if(updateModels==null){
  546.                 throw this.newServiceExceptionParameterUpdateModelsIsNull();
  547.             }

  548.             // ISQLQueryObject
  549.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  550.             sqlQueryObject.setANDLogicOperator(true);
  551.             // Connection sql
  552.             connection = this.jdbcServiceManager.getConnection();
  553.        
  554.             // transaction
  555.             if(this.jdbcProperties.isAutomaticTransactionManagement()){
  556.                 oldValueAutoCommit = connection.getAutoCommit();
  557.                 connection.setAutoCommit(false);
  558.             }

  559.             this.serviceCRUD.updateFields(this.jdbcProperties,this.log,connection,sqlQueryObject,tableId,updateModels);
  560.            
  561.         }catch(ServiceException | NotImplementedException e){
  562.             rollback = true;
  563.             this.logError(e); throw e;
  564.         }catch(NotFoundException e){
  565.             rollback = true;
  566.             this.logDebug(e); throw e;
  567.         }catch(Exception e){
  568.             rollback = true;
  569.             this.logError(e); throw this.newServiceExceptionUpdateFieldsNotCompleted(e);
  570.         }finally{
  571.             this.releaseResources(rollback, connection, oldValueAutoCommit);
  572.         }

  573.     }

  574.     @Override
  575.     public void updateOrCreate(IdConfigurazioneFiltro oldId, ConfigurazioneFiltro configurazioneFiltro) throws ServiceException, NotImplementedException {
  576.         try{
  577.             this.updateOrCreate(oldId, configurazioneFiltro, false, null);
  578.         }catch(ValidationException vE){
  579.             // not possible
  580.             throw new ServiceException(vE.getMessage(), vE);
  581.         }
  582.     }
  583.    
  584.     @Override
  585.     public void updateOrCreate(IdConfigurazioneFiltro oldId, ConfigurazioneFiltro configurazioneFiltro, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws ServiceException, NotImplementedException {
  586.         try{
  587.             this.updateOrCreate(oldId, configurazioneFiltro, false, idMappingResolutionBehaviour);
  588.         }catch(ValidationException vE){
  589.             // not possible
  590.             throw new ServiceException(vE.getMessage(), vE);
  591.         }
  592.     }

  593.     @Override
  594.     public void updateOrCreate(IdConfigurazioneFiltro oldId, ConfigurazioneFiltro configurazioneFiltro, boolean validate) throws ServiceException, NotImplementedException, ValidationException {
  595.         this.updateOrCreate(oldId, configurazioneFiltro, validate, null);
  596.     }

  597.     @Override
  598.     public void updateOrCreate(IdConfigurazioneFiltro oldId, ConfigurazioneFiltro configurazioneFiltro, boolean validate, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws ServiceException, NotImplementedException, ValidationException {
  599.    
  600.         Connection connection = null;
  601.         boolean oldValueAutoCommit = false;
  602.         boolean rollback = false;
  603.         try{
  604.            
  605.             // check parameters
  606.             if(configurazioneFiltro==null){
  607.                 throw this.newServiceExceptionParameterIsNull();
  608.             }
  609.             if(oldId==null){
  610.                 throw this.newServiceExceptionParameterOldIdIsNull();
  611.             }

  612.             // validate
  613.             if(validate){
  614.                 this.validate(configurazioneFiltro);
  615.             }

  616.             // ISQLQueryObject
  617.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  618.             sqlQueryObject.setANDLogicOperator(true);
  619.             // Connection sql
  620.             connection = this.jdbcServiceManager.getConnection();
  621.        
  622.             // transaction
  623.             if(this.jdbcProperties.isAutomaticTransactionManagement()){
  624.                 oldValueAutoCommit = connection.getAutoCommit();
  625.                 connection.setAutoCommit(false);
  626.             }

  627.             this.serviceCRUD.updateOrCreate(this.jdbcProperties,this.log,connection,sqlQueryObject,oldId,configurazioneFiltro,idMappingResolutionBehaviour);
  628.            
  629.         }catch(ServiceException | NotImplementedException | ValidationException e){
  630.             rollback = true;
  631.             this.logError(e); throw e;
  632.         }catch(Exception e){
  633.             rollback = true;
  634.             this.logError(e); throw new ServiceException("UpdateOrCreate not completed: "+e.getMessage(),e);
  635.         }finally{
  636.             this.releaseResources(rollback, connection, oldValueAutoCommit);
  637.         }

  638.     }
  639.    
  640.     @Override
  641.     public void updateOrCreate(long tableId, ConfigurazioneFiltro configurazioneFiltro) throws ServiceException, NotImplementedException {
  642.         try{
  643.             this.updateOrCreate(tableId, configurazioneFiltro, false, null);
  644.         }catch(ValidationException vE){
  645.             // not possible
  646.             throw new ServiceException(vE.getMessage(), vE);
  647.         }
  648.     }
  649.    
  650.     @Override
  651.     public void updateOrCreate(long tableId, ConfigurazioneFiltro configurazioneFiltro, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws ServiceException, NotImplementedException {
  652.         try{
  653.             this.updateOrCreate(tableId, configurazioneFiltro, false, idMappingResolutionBehaviour);
  654.         }catch(ValidationException vE){
  655.             // not possible
  656.             throw new ServiceException(vE.getMessage(), vE);
  657.         }
  658.     }

  659.     @Override
  660.     public void updateOrCreate(long tableId, ConfigurazioneFiltro configurazioneFiltro, boolean validate) throws ServiceException, NotImplementedException, ValidationException {
  661.         this.updateOrCreate(tableId, configurazioneFiltro, validate, null);
  662.     }

  663.     @Override
  664.     public void updateOrCreate(long tableId, ConfigurazioneFiltro configurazioneFiltro, boolean validate, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws ServiceException, NotImplementedException, ValidationException {

  665.         Connection connection = null;
  666.         boolean oldValueAutoCommit = false;
  667.         boolean rollback = false;
  668.         try{
  669.            
  670.             // check parameters
  671.             if(configurazioneFiltro==null){
  672.                 throw this.newServiceExceptionParameterIsNull();
  673.             }
  674.             if(tableId<=0){
  675.                 throw this.newServiceExceptionParameterIsLessEqualsZero();
  676.             }

  677.             // validate
  678.             if(validate){
  679.                 this.validate(configurazioneFiltro);
  680.             }

  681.             // ISQLQueryObject
  682.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  683.             sqlQueryObject.setANDLogicOperator(true);
  684.             // Connection sql
  685.             connection = this.jdbcServiceManager.getConnection();
  686.        
  687.             // transaction
  688.             if(this.jdbcProperties.isAutomaticTransactionManagement()){
  689.                 oldValueAutoCommit = connection.getAutoCommit();
  690.                 connection.setAutoCommit(false);
  691.             }

  692.             this.serviceCRUD.updateOrCreate(this.jdbcProperties,this.log,connection,sqlQueryObject,tableId,configurazioneFiltro,idMappingResolutionBehaviour);

  693.         }catch(ServiceException | NotImplementedException | ValidationException e){
  694.             rollback = true;
  695.             this.logError(e); throw e;
  696.         }catch(Exception e){
  697.             rollback = true;
  698.             this.logError(e); throw new ServiceException("UpdateOrCreate not completed: "+e.getMessage(),e);
  699.         }finally{
  700.             this.releaseResources(rollback, connection, oldValueAutoCommit);
  701.         }

  702.     }
  703.    
  704.     @Override
  705.     public void delete(ConfigurazioneFiltro configurazioneFiltro) throws ServiceException,NotImplementedException {
  706.        
  707.         Connection connection = null;
  708.         boolean oldValueAutoCommit = false;
  709.         boolean rollback = false;
  710.         try{
  711.            
  712.             // check parameters
  713.             if(configurazioneFiltro==null){
  714.                 throw this.newServiceExceptionParameterIsNull();
  715.             }

  716.             // ISQLQueryObject
  717.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  718.             sqlQueryObject.setANDLogicOperator(true);
  719.             // Connection sql
  720.             connection = this.jdbcServiceManager.getConnection();

  721.             // transaction
  722.             if(this.jdbcProperties.isAutomaticTransactionManagement()){
  723.                 oldValueAutoCommit = connection.getAutoCommit();
  724.                 connection.setAutoCommit(false);
  725.             }

  726.             this.serviceCRUD.delete(this.jdbcProperties,this.log,connection,sqlQueryObject,configurazioneFiltro);  

  727.         }catch(ServiceException | NotImplementedException e){
  728.             rollback = true;
  729.             this.logError(e); throw e;
  730.         }catch(Exception e){
  731.             rollback = true;
  732.             this.logError(e); throw new ServiceException("Delete not completed: "+e.getMessage(),e);
  733.         }finally{
  734.             this.releaseResources(rollback, connection, oldValueAutoCommit);
  735.         }
  736.    
  737.     }
  738.    

  739.     @Override
  740.     public void deleteById(IdConfigurazioneFiltro id) throws ServiceException, NotImplementedException {

  741.         Connection connection = null;
  742.         boolean oldValueAutoCommit = false;
  743.         boolean rollback = false;
  744.         try{
  745.            
  746.             // check parameters
  747.             if(id==null){
  748.                 throw this.newServiceExceptionParameterIdIsNull();
  749.             }

  750.             // ISQLQueryObject
  751.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  752.             sqlQueryObject.setANDLogicOperator(true);
  753.             // Connection sql
  754.             connection = this.jdbcServiceManager.getConnection();

  755.             // transaction
  756.             if(this.jdbcProperties.isAutomaticTransactionManagement()){
  757.                 oldValueAutoCommit = connection.getAutoCommit();
  758.                 connection.setAutoCommit(false);
  759.             }

  760.             this.serviceCRUD.deleteById(this.jdbcProperties,this.log,connection,sqlQueryObject,id);        

  761.         }catch(ServiceException | NotImplementedException e){
  762.             rollback = true;
  763.             this.logError(e); throw e;
  764.         }catch(Exception e){
  765.             rollback = true;
  766.             this.logError(e); throw new ServiceException("DeleteById not completed: "+e.getMessage(),e);
  767.         }finally{
  768.             this.releaseResources(rollback, connection, oldValueAutoCommit);
  769.         }

  770.     }

  771.     @Override
  772.     public NonNegativeNumber deleteAll() throws ServiceException, NotImplementedException {

  773.         Connection connection = null;
  774.         boolean oldValueAutoCommit = false;
  775.         boolean rollback = false;
  776.         try{

  777.             // ISQLQueryObject
  778.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  779.             sqlQueryObject.setANDLogicOperator(true);
  780.             // Connection sql
  781.             connection = this.jdbcServiceManager.getConnection();
  782.        
  783.             // transaction
  784.             if(this.jdbcProperties.isAutomaticTransactionManagement()){
  785.                 oldValueAutoCommit = connection.getAutoCommit();
  786.                 connection.setAutoCommit(false);
  787.             }

  788.             return this.serviceCRUD.deleteAll(this.jdbcProperties,this.log,connection,sqlQueryObject);  

  789.         }catch(ServiceException | NotImplementedException e){
  790.             rollback = true;
  791.             this.logError(e); throw e;
  792.         }catch(Exception e){
  793.             rollback = true;
  794.             this.logError(e); throw new ServiceException("DeleteAll not completed: "+e.getMessage(),e);
  795.         }finally{
  796.             this.releaseResources(rollback, connection, oldValueAutoCommit);
  797.         }
  798.    
  799.     }

  800.     @Override
  801.     public NonNegativeNumber deleteAll(IExpression expression) throws ServiceException, NotImplementedException {
  802.        
  803.         Connection connection = null;
  804.         boolean oldValueAutoCommit = false;
  805.         boolean rollback = false;
  806.         try{
  807.            
  808.             // check parameters
  809.             if(expression==null){
  810.                 throw this.newServiceExceptionParameterExpressionIsNull();
  811.             }
  812.             if( ! (expression instanceof JDBCExpression) ){
  813.                 throw this.newServiceExceptionParameterExpressionWrongType(expression);
  814.             }
  815.             JDBCExpression jdbcExpression = (JDBCExpression) expression;
  816.             this.logJDBCExpression(jdbcExpression);
  817.        
  818.             // ISQLQueryObject
  819.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  820.             sqlQueryObject.setANDLogicOperator(true);
  821.             // Connection sql
  822.             connection = this.jdbcServiceManager.getConnection();

  823.             // transaction
  824.             if(this.jdbcProperties.isAutomaticTransactionManagement()){
  825.                 oldValueAutoCommit = connection.getAutoCommit();
  826.                 connection.setAutoCommit(false);
  827.             }

  828.             return this.serviceCRUD.deleteAll(this.jdbcProperties,this.log,connection,sqlQueryObject,jdbcExpression);
  829.    
  830.         }catch(ServiceException | NotImplementedException e){
  831.             rollback = true;
  832.             this.logError(e); throw e;
  833.         }catch(Exception e){
  834.             rollback = true;
  835.             this.logError(e); throw new ServiceException("DeleteAll(expression) not completed: "+e.getMessage(),e);
  836.         }finally{
  837.             this.releaseResources(rollback, connection, oldValueAutoCommit);
  838.         }
  839.    
  840.     }
  841.    
  842.     // -- DB
  843.    
  844.     @Override
  845.     public void deleteById(long tableId) throws ServiceException, NotImplementedException {
  846.        
  847.         Connection connection = null;
  848.         boolean oldValueAutoCommit = false;
  849.         boolean rollback = false;
  850.         try{
  851.            
  852.             // check parameters
  853.             if(tableId<=0){
  854.                 throw new ServiceException("Parameter 'tableId' is less equals 0");
  855.             }
  856.        
  857.             // ISQLQueryObject
  858.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  859.             sqlQueryObject.setANDLogicOperator(true);
  860.             // Connection sql
  861.             connection = this.jdbcServiceManager.getConnection();

  862.             // transaction
  863.             if(this.jdbcProperties.isAutomaticTransactionManagement()){
  864.                 oldValueAutoCommit = connection.getAutoCommit();
  865.                 connection.setAutoCommit(false);
  866.             }

  867.             this.serviceCRUD.deleteById(this.jdbcProperties,this.log,connection,sqlQueryObject,tableId);
  868.    
  869.         }catch(ServiceException | NotImplementedException e){
  870.             rollback = true;
  871.             this.logError(e); throw e;
  872.         }catch(Exception e){
  873.             rollback = true;
  874.             this.logError(e); throw new ServiceException("DeleteById(tableId) not completed: "+e.getMessage(),e);
  875.         }finally{
  876.             this.releaseResources(rollback, connection, oldValueAutoCommit);
  877.         }
  878.    
  879.     }
  880.    
  881.     @Override
  882.     public int nativeUpdate(String sql,Object ... param) throws ServiceException, NotImplementedException {
  883.        
  884.         Connection connection = null;
  885.         boolean oldValueAutoCommit = false;
  886.         boolean rollback = false;
  887.         try{
  888.            
  889.             // check parameters
  890.             if(sql==null){
  891.                 throw new ServiceException("Parameter 'sql' is null");
  892.             }
  893.        
  894.             // ISQLQueryObject
  895.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  896.             sqlQueryObject.setANDLogicOperator(true);
  897.             // Connection sql
  898.             connection = this.jdbcServiceManager.getConnection();

  899.             // transaction
  900.             if(this.jdbcProperties.isAutomaticTransactionManagement()){
  901.                 oldValueAutoCommit = connection.getAutoCommit();
  902.                 connection.setAutoCommit(false);
  903.             }

  904.             return this.serviceCRUD.nativeUpdate(this.jdbcProperties,this.log,connection,sqlQueryObject,sql,param);
  905.    
  906.         }catch(ServiceException | NotImplementedException e){
  907.             rollback = true;
  908.             this.logError(e); throw e;
  909.         }catch(Exception e){
  910.             rollback = true;
  911.             this.logError(e); throw new ServiceException("DeleteById(tableId) not completed: "+e.getMessage(),e);
  912.         }finally{
  913.             this.releaseResources(rollback, connection, oldValueAutoCommit);
  914.         }
  915.    
  916.     }
  917.    
  918. }