JDBCTransazioneService.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.jdbc.IJDBCServiceCRUDWithId;
  22. import java.lang.String;

  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.transazioni.Transazione;
  34. import org.openspcoop2.core.transazioni.dao.ITransazioneService;
  35. import org.openspcoop2.core.transazioni.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.transazioni.Transazione}
  40.  *
  41.  * @author Poli Andrea (poli@link.it)
  42.  * @author $Author$
  43.  * @version $Rev$, $Date$
  44.  */

  45. public class JDBCTransazioneService extends JDBCTransazioneServiceSearch  implements ITransazioneService {


  46.     private IJDBCServiceCRUDWithId<Transazione, String, JDBCServiceManager> serviceCRUD = null;
  47.     public JDBCTransazioneService(JDBCServiceManager jdbcServiceManager) throws ServiceException {
  48.         super(jdbcServiceManager);
  49.         String msgInit = JDBCTransazioneService.class.getName()+ " initialized";
  50.         this.log.debug(msgInit);
  51.         this.serviceCRUD = JDBCProperties.getInstance(org.openspcoop2.core.transazioni.dao.jdbc.JDBCServiceManager.class.getPackage(),ProjectInfo.getInstance()).getServiceCRUD("transazione");
  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+Transazione.class.getName()+") 'transazione' is null");
  57.     }
  58.     private ServiceException newServiceExceptionParameterUpdateFieldsIsNull(){
  59.         return new ServiceException(PARAMETER_TYPE_PREFIX+UpdateField.class.getName()+") 'updateFields' is null");
  60.     }
  61.     private ServiceException newServiceExceptionParameterOldIdIsNull(){
  62.         return new ServiceException(PARAMETER_TYPE_PREFIX+String.class.getName()+") 'oldId' is null");
  63.     }
  64.     private ServiceException newServiceExceptionParameterConditionIsNull(){
  65.         return new ServiceException(PARAMETER_TYPE_PREFIX+IExpression.class.getName()+") 'condition' is null");
  66.     }
  67.     private ServiceException newServiceExceptionParameterUpdateModelsIsNull(){
  68.         return new ServiceException(PARAMETER_TYPE_PREFIX+UpdateModel.class.getName()+") 'updateModels' is null");
  69.     }
  70.    
  71.     private ServiceException newServiceExceptionUpdateFieldsNotCompleted(Exception e){
  72.         return new ServiceException("UpdateFields not completed: "+e.getMessage(),e);
  73.     }
  74.    
  75.    
  76.     private void releaseResources(boolean rollback, Connection connection, boolean oldValueAutoCommit) throws ServiceException {
  77.         if(this.jdbcProperties.isAutomaticTransactionManagement()){
  78.             manageTransaction(rollback, connection);
  79.             try{
  80.                 if(connection!=null)
  81.                     connection.setAutoCommit(oldValueAutoCommit);
  82.             }catch(Exception eIgnore){
  83.                 // ignore
  84.             }
  85.         }
  86.         if(connection!=null){
  87.             this.jdbcServiceManager.closeConnection(connection);
  88.         }
  89.     }
  90.     private void manageTransaction(boolean rollback, Connection connection) {
  91.         if(rollback){
  92.             try{
  93.                 if(connection!=null)
  94.                     connection.rollback();
  95.             }catch(Exception eIgnore){
  96.                 // ignore
  97.             }
  98.         }else{
  99.             try{
  100.                 if(connection!=null)
  101.                     connection.commit();
  102.             }catch(Exception eIgnore){
  103.                 // ignore
  104.             }
  105.         }
  106.     }
  107.    
  108.    
  109.    
  110.     @Override
  111.     public void create(Transazione transazione) throws ServiceException, NotImplementedException {
  112.         try{
  113.             this.create(transazione, false, null);
  114.         }catch(ValidationException vE){
  115.             // not possible
  116.             throw new ServiceException(vE.getMessage(), vE);
  117.         }
  118.     }
  119.    
  120.     @Override
  121.     public void create(Transazione transazione, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws ServiceException, NotImplementedException {
  122.         try{
  123.             this.create(transazione, false, idMappingResolutionBehaviour);
  124.         }catch(ValidationException vE){
  125.             // not possible
  126.             throw new ServiceException(vE.getMessage(), vE);
  127.         }
  128.     }
  129.    
  130.     @Override
  131.     public void create(Transazione transazione, boolean validate) throws ServiceException, NotImplementedException, ValidationException {
  132.         this.create(transazione, validate, null);
  133.     }
  134.    
  135.     @Override
  136.     public void create(Transazione transazione, boolean validate, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws ServiceException, NotImplementedException, ValidationException {
  137.        
  138.         Connection connection = null;
  139.         boolean oldValueAutoCommit = false;
  140.         boolean rollback = false;
  141.         try{
  142.            
  143.             // check parameters
  144.             if(transazione==null){
  145.                 throw this.newServiceExceptionParameterIsNull();
  146.             }
  147.            
  148.             // validate
  149.             if(validate){
  150.                 this.validate(transazione);
  151.             }

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

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

  174.     }

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

  215.             // validate
  216.             if(validate){
  217.                 this.validate(transazione);
  218.             }

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

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

  244.     }
  245.    
  246.    
  247.     @Override
  248.     public void updateFields(String id, UpdateField ... updateFields) throws ServiceException, NotFoundException, NotImplementedException {
  249.    
  250.         Connection connection = null;
  251.         boolean oldValueAutoCommit = false;
  252.         boolean rollback = false;
  253.         try{
  254.            
  255.             // check parameters
  256.             if(id==null){
  257.                 throw this.newServiceExceptionParameterIdIsNull();
  258.             }
  259.             if(updateFields==null){
  260.                 throw this.newServiceExceptionParameterUpdateFieldsIsNull();
  261.             }

  262.             // ISQLQueryObject
  263.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  264.             sqlQueryObject.setANDLogicOperator(true);
  265.             // Connection sql
  266.             connection = this.jdbcServiceManager.getConnection();
  267.        
  268.             // transaction
  269.             if(this.jdbcProperties.isAutomaticTransactionManagement()){
  270.                 oldValueAutoCommit = connection.getAutoCommit();
  271.                 connection.setAutoCommit(false);
  272.             }

  273.             this.serviceCRUD.updateFields(this.jdbcProperties,this.log,connection,sqlQueryObject,id,updateFields);
  274.            
  275.         }catch(ServiceException | NotImplementedException e){
  276.             rollback = true;
  277.             this.logError(e); throw e;
  278.         }catch(NotFoundException e){
  279.             rollback = true;
  280.             this.logDebug(e); throw e;
  281.         }catch(Exception e){
  282.             rollback = true;
  283.             this.logError(e); throw this.newServiceExceptionUpdateFieldsNotCompleted(e);
  284.         }finally{
  285.             this.releaseResources(rollback, connection, oldValueAutoCommit);
  286.         }

  287.     }
  288.    
  289.     @Override
  290.     public void updateFields(String id, IExpression condition, UpdateField ... updateFields) throws ServiceException, NotFoundException, NotImplementedException {
  291.    
  292.         Connection connection = null;
  293.         boolean oldValueAutoCommit = false;
  294.         boolean rollback = false;
  295.         try{
  296.            
  297.             // check parameters
  298.             if(id==null){
  299.                 throw this.newServiceExceptionParameterIdIsNull();
  300.             }
  301.             if(condition==null){
  302.                 throw this.newServiceExceptionParameterConditionIsNull();
  303.             }
  304.             if(updateFields==null){
  305.                 throw this.newServiceExceptionParameterUpdateFieldsIsNull();
  306.             }

  307.             // ISQLQueryObject
  308.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  309.             sqlQueryObject.setANDLogicOperator(true);
  310.             // Connection sql
  311.             connection = this.jdbcServiceManager.getConnection();
  312.        
  313.             // transaction
  314.             if(this.jdbcProperties.isAutomaticTransactionManagement()){
  315.                 oldValueAutoCommit = connection.getAutoCommit();
  316.                 connection.setAutoCommit(false);
  317.             }

  318.             this.serviceCRUD.updateFields(this.jdbcProperties,this.log,connection,sqlQueryObject,id,condition,updateFields);
  319.            
  320.         }catch(ServiceException | NotImplementedException e){
  321.             rollback = true;
  322.             this.logError(e); throw e;
  323.         }catch(NotFoundException e){
  324.             rollback = true;
  325.             this.logDebug(e); throw e;
  326.         }catch(Exception e){
  327.             rollback = true;
  328.             this.logError(e); throw this.newServiceExceptionUpdateFieldsNotCompleted(e);
  329.         }finally{
  330.             this.releaseResources(rollback, connection, oldValueAutoCommit);
  331.         }

  332.     }

  333.     @Override
  334.     public void updateFields(String id, UpdateModel ... updateModels) throws ServiceException, NotFoundException, NotImplementedException {
  335.    
  336.         Connection connection = null;
  337.         boolean oldValueAutoCommit = false;
  338.         boolean rollback = false;
  339.         try{
  340.            
  341.             // check parameters
  342.             if(id==null){
  343.                 throw this.newServiceExceptionParameterIdIsNull();
  344.             }
  345.             if(updateModels==null){
  346.                 throw this.newServiceExceptionParameterUpdateModelsIsNull();
  347.             }

  348.             // ISQLQueryObject
  349.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  350.             sqlQueryObject.setANDLogicOperator(true);
  351.             // Connection sql
  352.             connection = this.jdbcServiceManager.getConnection();
  353.        
  354.             // transaction
  355.             if(this.jdbcProperties.isAutomaticTransactionManagement()){
  356.                 oldValueAutoCommit = connection.getAutoCommit();
  357.                 connection.setAutoCommit(false);
  358.             }

  359.             this.serviceCRUD.updateFields(this.jdbcProperties,this.log,connection,sqlQueryObject,id,updateModels);
  360.            
  361.         }catch(ServiceException | NotImplementedException e){
  362.             rollback = true;
  363.             this.logError(e); throw e;
  364.         }catch(NotFoundException e){
  365.             rollback = true;
  366.             this.logDebug(e); throw e;
  367.         }catch(Exception e){
  368.             rollback = true;
  369.             this.logError(e); throw this.newServiceExceptionUpdateFieldsNotCompleted(e);
  370.         }finally{
  371.             this.releaseResources(rollback, connection, oldValueAutoCommit);
  372.         }

  373.     }


  374.     @Override
  375.     public void updateOrCreate(String oldId, Transazione transazione) throws ServiceException, NotImplementedException {
  376.         try{
  377.             this.updateOrCreate(oldId, transazione, false, null);
  378.         }catch(ValidationException vE){
  379.             // not possible
  380.             throw new ServiceException(vE.getMessage(), vE);
  381.         }
  382.     }
  383.    
  384.     @Override
  385.     public void updateOrCreate(String oldId, Transazione transazione, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws ServiceException, NotImplementedException {
  386.         try{
  387.             this.updateOrCreate(oldId, transazione, false, idMappingResolutionBehaviour);
  388.         }catch(ValidationException vE){
  389.             // not possible
  390.             throw new ServiceException(vE.getMessage(), vE);
  391.         }
  392.     }

  393.     @Override
  394.     public void updateOrCreate(String oldId, Transazione transazione, boolean validate) throws ServiceException, NotImplementedException, ValidationException {
  395.         this.updateOrCreate(oldId, transazione, validate, null);
  396.     }

  397.     @Override
  398.     public void updateOrCreate(String oldId, Transazione transazione, boolean validate, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws ServiceException, NotImplementedException, ValidationException {
  399.    
  400.         Connection connection = null;
  401.         boolean oldValueAutoCommit = false;
  402.         boolean rollback = false;
  403.         try{
  404.            
  405.             // check parameters
  406.             if(transazione==null){
  407.                 throw this.newServiceExceptionParameterIsNull();
  408.             }
  409.             if(oldId==null){
  410.                 throw this.newServiceExceptionParameterOldIdIsNull();
  411.             }

  412.             // validate
  413.             if(validate){
  414.                 this.validate(transazione);
  415.             }

  416.             // ISQLQueryObject
  417.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  418.             sqlQueryObject.setANDLogicOperator(true);
  419.             // Connection sql
  420.             connection = this.jdbcServiceManager.getConnection();
  421.        
  422.             // transaction
  423.             if(this.jdbcProperties.isAutomaticTransactionManagement()){
  424.                 oldValueAutoCommit = connection.getAutoCommit();
  425.                 connection.setAutoCommit(false);
  426.             }

  427.             this.serviceCRUD.updateOrCreate(this.jdbcProperties,this.log,connection,sqlQueryObject,oldId,transazione,idMappingResolutionBehaviour);
  428.            
  429.         }catch(ServiceException | NotImplementedException | ValidationException e){
  430.             rollback = true;
  431.             this.logError(e); throw e;
  432.         }catch(Exception e){
  433.             rollback = true;
  434.             this.logError(e); throw new ServiceException("UpdateOrCreate not completed: "+e.getMessage(),e);
  435.         }finally{
  436.             this.releaseResources(rollback, connection, oldValueAutoCommit);
  437.         }

  438.     }
  439.    
  440.    
  441.     @Override
  442.     public void delete(Transazione transazione) throws ServiceException,NotImplementedException {
  443.        
  444.         Connection connection = null;
  445.         boolean oldValueAutoCommit = false;
  446.         boolean rollback = false;
  447.         try{
  448.            
  449.             // check parameters
  450.             if(transazione==null){
  451.                 throw this.newServiceExceptionParameterIsNull();
  452.             }

  453.             // ISQLQueryObject
  454.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  455.             sqlQueryObject.setANDLogicOperator(true);
  456.             // Connection sql
  457.             connection = this.jdbcServiceManager.getConnection();

  458.             // transaction
  459.             if(this.jdbcProperties.isAutomaticTransactionManagement()){
  460.                 oldValueAutoCommit = connection.getAutoCommit();
  461.                 connection.setAutoCommit(false);
  462.             }

  463.             this.serviceCRUD.delete(this.jdbcProperties,this.log,connection,sqlQueryObject,transazione);    

  464.         }catch(ServiceException | NotImplementedException e){
  465.             rollback = true;
  466.             this.logError(e); throw e;
  467.         }catch(Exception e){
  468.             rollback = true;
  469.             this.logError(e); throw new ServiceException("Delete not completed: "+e.getMessage(),e);
  470.         }finally{
  471.             this.releaseResources(rollback, connection, oldValueAutoCommit);
  472.         }
  473.    
  474.     }
  475.    

  476.     @Override
  477.     public void deleteById(String id) throws ServiceException, NotImplementedException {

  478.         Connection connection = null;
  479.         boolean oldValueAutoCommit = false;
  480.         boolean rollback = false;
  481.         try{
  482.            
  483.             // check parameters
  484.             if(id==null){
  485.                 throw this.newServiceExceptionParameterIdIsNull();
  486.             }

  487.             // ISQLQueryObject
  488.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  489.             sqlQueryObject.setANDLogicOperator(true);
  490.             // Connection sql
  491.             connection = this.jdbcServiceManager.getConnection();

  492.             // transaction
  493.             if(this.jdbcProperties.isAutomaticTransactionManagement()){
  494.                 oldValueAutoCommit = connection.getAutoCommit();
  495.                 connection.setAutoCommit(false);
  496.             }

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

  498.         }catch(ServiceException | NotImplementedException e){
  499.             rollback = true;
  500.             this.logError(e); throw e;
  501.         }catch(Exception e){
  502.             rollback = true;
  503.             this.logError(e); throw new ServiceException("DeleteById not completed: "+e.getMessage(),e);
  504.         }finally{
  505.             this.releaseResources(rollback, connection, oldValueAutoCommit);
  506.         }

  507.     }

  508.     @Override
  509.     public NonNegativeNumber deleteAll() throws ServiceException, NotImplementedException {

  510.         Connection connection = null;
  511.         boolean oldValueAutoCommit = false;
  512.         boolean rollback = false;
  513.         try{

  514.             // ISQLQueryObject
  515.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  516.             sqlQueryObject.setANDLogicOperator(true);
  517.             // Connection sql
  518.             connection = this.jdbcServiceManager.getConnection();
  519.        
  520.             // transaction
  521.             if(this.jdbcProperties.isAutomaticTransactionManagement()){
  522.                 oldValueAutoCommit = connection.getAutoCommit();
  523.                 connection.setAutoCommit(false);
  524.             }

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

  526.         }catch(ServiceException | NotImplementedException e){
  527.             rollback = true;
  528.             this.logError(e); throw e;
  529.         }catch(Exception e){
  530.             rollback = true;
  531.             this.logError(e); throw new ServiceException("DeleteAll not completed: "+e.getMessage(),e);
  532.         }finally{
  533.             this.releaseResources(rollback, connection, oldValueAutoCommit);
  534.         }
  535.    
  536.     }

  537.     @Override
  538.     public NonNegativeNumber deleteAll(IExpression expression) throws ServiceException, NotImplementedException {
  539.        
  540.         Connection connection = null;
  541.         boolean oldValueAutoCommit = false;
  542.         boolean rollback = false;
  543.         try{
  544.            
  545.             // check parameters
  546.             if(expression==null){
  547.                 throw this.newServiceExceptionParameterExpressionIsNull();
  548.             }
  549.             if( ! (expression instanceof JDBCExpression) ){
  550.                 throw this.newServiceExceptionParameterExpressionWrongType(expression);
  551.             }
  552.             JDBCExpression jdbcExpression = (JDBCExpression) expression;
  553.             this.logJDBCExpression(jdbcExpression);
  554.        
  555.             // ISQLQueryObject
  556.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  557.             sqlQueryObject.setANDLogicOperator(true);
  558.             // Connection sql
  559.             connection = this.jdbcServiceManager.getConnection();

  560.             // transaction
  561.             if(this.jdbcProperties.isAutomaticTransactionManagement()){
  562.                 oldValueAutoCommit = connection.getAutoCommit();
  563.                 connection.setAutoCommit(false);
  564.             }

  565.             return this.serviceCRUD.deleteAll(this.jdbcProperties,this.log,connection,sqlQueryObject,jdbcExpression);
  566.    
  567.         }catch(ServiceException | NotImplementedException e){
  568.             rollback = true;
  569.             this.logError(e); throw e;
  570.         }catch(Exception e){
  571.             rollback = true;
  572.             this.logError(e); throw new ServiceException("DeleteAll(expression) not completed: "+e.getMessage(),e);
  573.         }finally{
  574.             this.releaseResources(rollback, connection, oldValueAutoCommit);
  575.         }
  576.    
  577.     }
  578.    
  579.    
  580.     @Override
  581.     public int nativeUpdate(String sql,Object ... param) throws ServiceException, NotImplementedException {
  582.        
  583.         Connection connection = null;
  584.         boolean oldValueAutoCommit = false;
  585.         boolean rollback = false;
  586.         try{
  587.            
  588.             // check parameters
  589.             if(sql==null){
  590.                 throw new ServiceException("Parameter 'sql' is null");
  591.             }
  592.        
  593.             // ISQLQueryObject
  594.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  595.             sqlQueryObject.setANDLogicOperator(true);
  596.             // Connection sql
  597.             connection = this.jdbcServiceManager.getConnection();

  598.             // transaction
  599.             if(this.jdbcProperties.isAutomaticTransactionManagement()){
  600.                 oldValueAutoCommit = connection.getAutoCommit();
  601.                 connection.setAutoCommit(false);
  602.             }

  603.             return this.serviceCRUD.nativeUpdate(this.jdbcProperties,this.log,connection,sqlQueryObject,sql,param);
  604.    
  605.         }catch(ServiceException | NotImplementedException e){
  606.             rollback = true;
  607.             this.logError(e); throw e;
  608.         }catch(Exception e){
  609.             rollback = true;
  610.             this.logError(e); throw new ServiceException("DeleteById(tableId) not completed: "+e.getMessage(),e);
  611.         }finally{
  612.             this.releaseResources(rollback, connection, oldValueAutoCommit);
  613.         }
  614.    
  615.     }
  616.    
  617. }