JDBCStatisticaMensileService.java

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

  21. import org.openspcoop2.generic_project.dao.jdbc.IJDBCServiceCRUDWithoutId;

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

  32. import org.openspcoop2.core.statistiche.StatisticaMensile;
  33. import org.openspcoop2.core.statistiche.dao.IDBStatisticaMensileService;
  34. import org.openspcoop2.core.statistiche.utils.ProjectInfo;

  35. import java.sql.Connection;

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

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

  44. public class JDBCStatisticaMensileService extends JDBCStatisticaMensileServiceSearch  implements IDBStatisticaMensileService {


  45.     private IJDBCServiceCRUDWithoutId<StatisticaMensile, JDBCServiceManager> serviceCRUD = null;
  46.     public JDBCStatisticaMensileService(JDBCServiceManager jdbcServiceManager) throws ServiceException {
  47.         super(jdbcServiceManager);
  48.         String msgInit = JDBCStatisticaMensileService.class.getName()+ " initialized";
  49.         this.log.debug(msgInit);
  50.         this.serviceCRUD = JDBCProperties.getInstance(org.openspcoop2.core.statistiche.dao.jdbc.JDBCServiceManager.class.getPackage(),ProjectInfo.getInstance()).getServiceCRUD("statisticaMensile");
  51.         this.serviceCRUD.setServiceManager(new JDBCLimitedServiceManager(this.jdbcServiceManager));
  52.     }

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

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

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

  173.     }

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

  211.             // validate
  212.             if(validate){
  213.                 this.validate(statisticaMensile);
  214.             }

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

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

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

  282.             // validate
  283.             if(validate){
  284.                 this.validate(statisticaMensile);
  285.             }

  286.             // ISQLQueryObject
  287.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  288.             sqlQueryObject.setANDLogicOperator(true);
  289.             // Connection sql
  290.             connection = this.jdbcServiceManager.getConnection();
  291.        
  292.             // transaction
  293.             if(this.jdbcProperties.isAutomaticTransactionManagement()){
  294.                 oldValueAutoCommit = connection.getAutoCommit();
  295.                 connection.setAutoCommit(false);
  296.             }

  297.             this.serviceCRUD.update(this.jdbcProperties,this.log,connection,sqlQueryObject,tableId,statisticaMensile,idMappingResolutionBehaviour);
  298.            
  299.         }catch(ServiceException | NotImplementedException | ValidationException e){
  300.             rollback = true;
  301.             this.logError(e); throw e;
  302.         }catch(NotFoundException e){
  303.             rollback = true;
  304.             this.logDebug(e); throw e;
  305.         }catch(Exception e){
  306.             rollback = true;
  307.             this.logError(e); throw new ServiceException("Update not completed: "+e.getMessage(),e);
  308.         }finally{
  309.             this.releaseResources(rollback, connection, oldValueAutoCommit);
  310.         }

  311.     }
  312.    
  313.     @Override
  314.     public void updateFields(StatisticaMensile statisticaMensile, UpdateField ... updateFields) throws ServiceException, NotFoundException, NotImplementedException {
  315.    
  316.         Connection connection = null;
  317.         boolean oldValueAutoCommit = false;
  318.         boolean rollback = false;
  319.         try{
  320.            
  321.             // check parameters
  322.             if(statisticaMensile==null){
  323.                 throw this.newServiceExceptionParameterIsNull();
  324.             }
  325.             if(updateFields==null){
  326.                 throw this.newServiceExceptionParameterUpdateFieldsIsNull();
  327.             }

  328.             // ISQLQueryObject
  329.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  330.             sqlQueryObject.setANDLogicOperator(true);
  331.             // Connection sql
  332.             connection = this.jdbcServiceManager.getConnection();
  333.        
  334.             // transaction
  335.             if(this.jdbcProperties.isAutomaticTransactionManagement()){
  336.                 oldValueAutoCommit = connection.getAutoCommit();
  337.                 connection.setAutoCommit(false);
  338.             }

  339.             this.serviceCRUD.updateFields(this.jdbcProperties,this.log,connection,sqlQueryObject,statisticaMensile,updateFields);
  340.            
  341.         }catch(ServiceException | NotImplementedException e){
  342.             rollback = true;
  343.             this.logError(e); throw e;
  344.         }catch(NotFoundException e){
  345.             rollback = true;
  346.             this.logDebug(e); throw e;
  347.         }catch(Exception e){
  348.             rollback = true;
  349.             this.logError(e); throw this.newServiceExceptionUpdateFieldsNotCompleted(e);
  350.         }finally{
  351.             this.releaseResources(rollback, connection, oldValueAutoCommit);
  352.         }

  353.     }
  354.    
  355.     @Override
  356.     public void updateFields(StatisticaMensile statisticaMensile, IExpression condition, UpdateField ... updateFields) throws ServiceException, NotFoundException, NotImplementedException {
  357.    
  358.         Connection connection = null;
  359.         boolean oldValueAutoCommit = false;
  360.         boolean rollback = false;
  361.         try{
  362.            
  363.             // check parameters
  364.             if(statisticaMensile==null){
  365.                 throw this.newServiceExceptionParameterIsNull();
  366.             }
  367.             if(condition==null){
  368.                 throw this.newServiceExceptionParameterConditionIsNull();
  369.             }
  370.             if(updateFields==null){
  371.                 throw this.newServiceExceptionParameterUpdateFieldsIsNull();
  372.             }

  373.             // ISQLQueryObject
  374.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  375.             sqlQueryObject.setANDLogicOperator(true);
  376.             // Connection sql
  377.             connection = this.jdbcServiceManager.getConnection();
  378.        
  379.             // transaction
  380.             if(this.jdbcProperties.isAutomaticTransactionManagement()){
  381.                 oldValueAutoCommit = connection.getAutoCommit();
  382.                 connection.setAutoCommit(false);
  383.             }

  384.             this.serviceCRUD.updateFields(this.jdbcProperties,this.log,connection,sqlQueryObject,statisticaMensile,condition,updateFields);
  385.            
  386.         }catch(ServiceException | NotImplementedException e){
  387.             rollback = true;
  388.             this.logError(e); throw e;
  389.         }catch(NotFoundException e){
  390.             rollback = true;
  391.             this.logDebug(e); throw e;
  392.         }catch(Exception e){
  393.             rollback = true;
  394.             this.logError(e); throw this.newServiceExceptionUpdateFieldsNotCompleted(e);
  395.         }finally{
  396.             this.releaseResources(rollback, connection, oldValueAutoCommit);
  397.         }

  398.     }

  399.     @Override
  400.     public void updateFields(StatisticaMensile statisticaMensile, UpdateModel ... updateModels) throws ServiceException, NotFoundException, NotImplementedException {
  401.    
  402.         Connection connection = null;
  403.         boolean oldValueAutoCommit = false;
  404.         boolean rollback = false;
  405.         try{
  406.            
  407.             // check parameters
  408.             if(statisticaMensile==null){
  409.                 throw this.newServiceExceptionParameterIsNull();
  410.             }
  411.             if(updateModels==null){
  412.                 throw this.newServiceExceptionParameterUpdateModelsIsNull();
  413.             }

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

  425.             this.serviceCRUD.updateFields(this.jdbcProperties,this.log,connection,sqlQueryObject,statisticaMensile,updateModels);
  426.            
  427.         }catch(ServiceException | NotImplementedException e){
  428.             rollback = true;
  429.             this.logError(e); throw e;
  430.         }catch(NotFoundException e){
  431.             rollback = true;
  432.             this.logDebug(e); throw e;
  433.         }catch(Exception e){
  434.             rollback = true;
  435.             this.logError(e); throw this.newServiceExceptionUpdateFieldsNotCompleted(e);
  436.         }finally{
  437.             this.releaseResources(rollback, connection, oldValueAutoCommit);
  438.         }

  439.     }

  440.     @Override
  441.     public void updateFields(long tableId, UpdateField ... updateFields) throws ServiceException, NotFoundException, NotImplementedException {
  442.    
  443.         Connection connection = null;
  444.         boolean oldValueAutoCommit = false;
  445.         boolean rollback = false;
  446.         try{
  447.            
  448.             // check parameters
  449.             if(tableId<=0){
  450.                 throw this.newServiceExceptionParameterIsLessEqualsZero();
  451.             }
  452.             if(updateFields==null){
  453.                 throw this.newServiceExceptionParameterUpdateFieldsIsNull();
  454.             }

  455.             // ISQLQueryObject
  456.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  457.             sqlQueryObject.setANDLogicOperator(true);
  458.             // Connection sql
  459.             connection = this.jdbcServiceManager.getConnection();
  460.        
  461.             // transaction
  462.             if(this.jdbcProperties.isAutomaticTransactionManagement()){
  463.                 oldValueAutoCommit = connection.getAutoCommit();
  464.                 connection.setAutoCommit(false);
  465.             }

  466.             this.serviceCRUD.updateFields(this.jdbcProperties,this.log,connection,sqlQueryObject,tableId,updateFields);
  467.            
  468.         }catch(ServiceException | NotImplementedException e){
  469.             rollback = true;
  470.             this.logError(e); throw e;
  471.         }catch(NotFoundException e){
  472.             rollback = true;
  473.             this.logDebug(e); throw e;
  474.         }catch(Exception e){
  475.             rollback = true;
  476.             this.logError(e); throw this.newServiceExceptionUpdateFieldsNotCompleted(e);
  477.         }finally{
  478.             this.releaseResources(rollback, connection, oldValueAutoCommit);
  479.         }

  480.     }
  481.    
  482.     @Override
  483.     public void updateFields(long tableId, IExpression condition, UpdateField ... updateFields) throws ServiceException, NotFoundException, NotImplementedException {
  484.    
  485.         Connection connection = null;
  486.         boolean oldValueAutoCommit = false;
  487.         boolean rollback = false;
  488.         try{
  489.            
  490.             // check parameters
  491.             if(tableId<=0){
  492.                 throw this.newServiceExceptionParameterIsLessEqualsZero();
  493.             }
  494.             if(condition==null){
  495.                 throw this.newServiceExceptionParameterConditionIsNull();
  496.             }
  497.             if(updateFields==null){
  498.                 throw this.newServiceExceptionParameterUpdateFieldsIsNull();
  499.             }

  500.             // ISQLQueryObject
  501.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  502.             sqlQueryObject.setANDLogicOperator(true);
  503.             // Connection sql
  504.             connection = this.jdbcServiceManager.getConnection();
  505.        
  506.             // transaction
  507.             if(this.jdbcProperties.isAutomaticTransactionManagement()){
  508.                 oldValueAutoCommit = connection.getAutoCommit();
  509.                 connection.setAutoCommit(false);
  510.             }

  511.             this.serviceCRUD.updateFields(this.jdbcProperties,this.log,connection,sqlQueryObject,tableId,condition,updateFields);
  512.            
  513.         }catch(ServiceException | NotImplementedException e){
  514.             rollback = true;
  515.             this.logError(e); throw e;
  516.         }catch(NotFoundException e){
  517.             rollback = true;
  518.             this.logDebug(e); throw e;
  519.         }catch(Exception e){
  520.             rollback = true;
  521.             this.logError(e); throw this.newServiceExceptionUpdateFieldsNotCompleted(e);
  522.         }finally{
  523.             this.releaseResources(rollback, connection, oldValueAutoCommit);
  524.         }

  525.     }

  526.     @Override
  527.     public void updateFields(long tableId, UpdateModel ... updateModels) throws ServiceException, NotFoundException, NotImplementedException {
  528.    
  529.         Connection connection = null;
  530.         boolean oldValueAutoCommit = false;
  531.         boolean rollback = false;
  532.         try{
  533.            
  534.             // check parameters
  535.             if(tableId<=0){
  536.                 throw this.newServiceExceptionParameterIsLessEqualsZero();
  537.             }
  538.             if(updateModels==null){
  539.                 throw this.newServiceExceptionParameterUpdateModelsIsNull();
  540.             }

  541.             // ISQLQueryObject
  542.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  543.             sqlQueryObject.setANDLogicOperator(true);
  544.             // Connection sql
  545.             connection = this.jdbcServiceManager.getConnection();
  546.        
  547.             // transaction
  548.             if(this.jdbcProperties.isAutomaticTransactionManagement()){
  549.                 oldValueAutoCommit = connection.getAutoCommit();
  550.                 connection.setAutoCommit(false);
  551.             }

  552.             this.serviceCRUD.updateFields(this.jdbcProperties,this.log,connection,sqlQueryObject,tableId,updateModels);
  553.            
  554.         }catch(ServiceException | NotImplementedException e){
  555.             rollback = true;
  556.             this.logError(e); throw e;
  557.         }catch(NotFoundException e){
  558.             rollback = true;
  559.             this.logDebug(e); throw e;
  560.         }catch(Exception e){
  561.             rollback = true;
  562.             this.logError(e); throw this.newServiceExceptionUpdateFieldsNotCompleted(e);
  563.         }finally{
  564.             this.releaseResources(rollback, connection, oldValueAutoCommit);
  565.         }

  566.     }

  567.     @Override
  568.     public void updateOrCreate(StatisticaMensile statisticaMensile) throws ServiceException, NotImplementedException {
  569.         try{
  570.             this.updateOrCreate(statisticaMensile, false, null);
  571.         }catch(ValidationException vE){
  572.             // not possible
  573.             throw new ServiceException(vE.getMessage(), vE);
  574.         }
  575.     }
  576.    
  577.     @Override
  578.     public void updateOrCreate(StatisticaMensile statisticaMensile, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws ServiceException, NotImplementedException {
  579.         try{
  580.             this.updateOrCreate(statisticaMensile, false, idMappingResolutionBehaviour);
  581.         }catch(ValidationException vE){
  582.             // not possible
  583.             throw new ServiceException(vE.getMessage(), vE);
  584.         }
  585.     }

  586.     @Override
  587.     public void updateOrCreate(StatisticaMensile statisticaMensile, boolean validate) throws ServiceException, NotImplementedException, ValidationException {
  588.         this.updateOrCreate(statisticaMensile, validate, null);
  589.     }

  590.     @Override
  591.     public void updateOrCreate(StatisticaMensile statisticaMensile, boolean validate, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws ServiceException, NotImplementedException, ValidationException {
  592.    
  593.         Connection connection = null;
  594.         boolean oldValueAutoCommit = false;
  595.         boolean rollback = false;
  596.         try{
  597.            
  598.             // check parameters
  599.             if(statisticaMensile==null){
  600.                 throw this.newServiceExceptionParameterIsNull();
  601.             }

  602.             // validate
  603.             if(validate){
  604.                 this.validate(statisticaMensile);
  605.             }

  606.             // ISQLQueryObject
  607.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  608.             sqlQueryObject.setANDLogicOperator(true);
  609.             // Connection sql
  610.             connection = this.jdbcServiceManager.getConnection();
  611.        
  612.             // transaction
  613.             if(this.jdbcProperties.isAutomaticTransactionManagement()){
  614.                 oldValueAutoCommit = connection.getAutoCommit();
  615.                 connection.setAutoCommit(false);
  616.             }

  617.             this.serviceCRUD.updateOrCreate(this.jdbcProperties,this.log,connection,sqlQueryObject,statisticaMensile,idMappingResolutionBehaviour);
  618.            
  619.         }catch(ServiceException | NotImplementedException | ValidationException e){
  620.             rollback = true;
  621.             this.logError(e); throw e;
  622.         }catch(Exception e){
  623.             rollback = true;
  624.             this.logError(e); throw new ServiceException("UpdateOrCreate not completed: "+e.getMessage(),e);
  625.         }finally{
  626.             this.releaseResources(rollback, connection, oldValueAutoCommit);
  627.         }

  628.     }
  629.    
  630.     @Override
  631.     public void updateOrCreate(long tableId, StatisticaMensile statisticaMensile) throws ServiceException, NotImplementedException {
  632.         try{
  633.             this.updateOrCreate(tableId, statisticaMensile, false, null);
  634.         }catch(ValidationException vE){
  635.             // not possible
  636.             throw new ServiceException(vE.getMessage(), vE);
  637.         }
  638.     }
  639.    
  640.     @Override
  641.     public void updateOrCreate(long tableId, StatisticaMensile statisticaMensile, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws ServiceException, NotImplementedException {
  642.         try{
  643.             this.updateOrCreate(tableId, statisticaMensile, false, idMappingResolutionBehaviour);
  644.         }catch(ValidationException vE){
  645.             // not possible
  646.             throw new ServiceException(vE.getMessage(), vE);
  647.         }
  648.     }

  649.     @Override
  650.     public void updateOrCreate(long tableId, StatisticaMensile statisticaMensile, boolean validate) throws ServiceException, NotImplementedException, ValidationException {
  651.         this.updateOrCreate(tableId, statisticaMensile, validate, null);
  652.     }

  653.     @Override
  654.     public void updateOrCreate(long tableId, StatisticaMensile statisticaMensile, boolean validate, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws ServiceException, NotImplementedException, ValidationException {

  655.         Connection connection = null;
  656.         boolean oldValueAutoCommit = false;
  657.         boolean rollback = false;
  658.         try{
  659.            
  660.             // check parameters
  661.             if(statisticaMensile==null){
  662.                 throw this.newServiceExceptionParameterIsNull();
  663.             }
  664.             if(tableId<=0){
  665.                 throw this.newServiceExceptionParameterIsLessEqualsZero();
  666.             }

  667.             // validate
  668.             if(validate){
  669.                 this.validate(statisticaMensile);
  670.             }

  671.             // ISQLQueryObject
  672.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  673.             sqlQueryObject.setANDLogicOperator(true);
  674.             // Connection sql
  675.             connection = this.jdbcServiceManager.getConnection();
  676.        
  677.             // transaction
  678.             if(this.jdbcProperties.isAutomaticTransactionManagement()){
  679.                 oldValueAutoCommit = connection.getAutoCommit();
  680.                 connection.setAutoCommit(false);
  681.             }

  682.             this.serviceCRUD.updateOrCreate(this.jdbcProperties,this.log,connection,sqlQueryObject,tableId,statisticaMensile,idMappingResolutionBehaviour);

  683.         }catch(ServiceException | NotImplementedException | ValidationException e){
  684.             rollback = true;
  685.             this.logError(e); throw e;
  686.         }catch(Exception e){
  687.             rollback = true;
  688.             this.logError(e); throw new ServiceException("UpdateOrCreate not completed: "+e.getMessage(),e);
  689.         }finally{
  690.             this.releaseResources(rollback, connection, oldValueAutoCommit);
  691.         }

  692.     }
  693.    
  694.     @Override
  695.     public void delete(StatisticaMensile statisticaMensile) throws ServiceException,NotImplementedException {
  696.        
  697.         Connection connection = null;
  698.         boolean oldValueAutoCommit = false;
  699.         boolean rollback = false;
  700.         try{
  701.            
  702.             // check parameters
  703.             if(statisticaMensile==null){
  704.                 throw this.newServiceExceptionParameterIsNull();
  705.             }

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

  711.             // transaction
  712.             if(this.jdbcProperties.isAutomaticTransactionManagement()){
  713.                 oldValueAutoCommit = connection.getAutoCommit();
  714.                 connection.setAutoCommit(false);
  715.             }

  716.             this.serviceCRUD.delete(this.jdbcProperties,this.log,connection,sqlQueryObject,statisticaMensile);  

  717.         }catch(ServiceException | NotImplementedException e){
  718.             rollback = true;
  719.             this.logError(e); throw e;
  720.         }catch(Exception e){
  721.             rollback = true;
  722.             this.logError(e); throw new ServiceException("Delete not completed: "+e.getMessage(),e);
  723.         }finally{
  724.             this.releaseResources(rollback, connection, oldValueAutoCommit);
  725.         }
  726.    
  727.     }
  728.    


  729.     @Override
  730.     public NonNegativeNumber deleteAll() throws ServiceException, NotImplementedException {

  731.         Connection connection = null;
  732.         boolean oldValueAutoCommit = false;
  733.         boolean rollback = false;
  734.         try{

  735.             // ISQLQueryObject
  736.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  737.             sqlQueryObject.setANDLogicOperator(true);
  738.             // Connection sql
  739.             connection = this.jdbcServiceManager.getConnection();
  740.        
  741.             // transaction
  742.             if(this.jdbcProperties.isAutomaticTransactionManagement()){
  743.                 oldValueAutoCommit = connection.getAutoCommit();
  744.                 connection.setAutoCommit(false);
  745.             }

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

  747.         }catch(ServiceException | NotImplementedException e){
  748.             rollback = true;
  749.             this.logError(e); throw e;
  750.         }catch(Exception e){
  751.             rollback = true;
  752.             this.logError(e); throw new ServiceException("DeleteAll not completed: "+e.getMessage(),e);
  753.         }finally{
  754.             this.releaseResources(rollback, connection, oldValueAutoCommit);
  755.         }
  756.    
  757.     }

  758.     @Override
  759.     public NonNegativeNumber deleteAll(IExpression expression) throws ServiceException, NotImplementedException {
  760.        
  761.         Connection connection = null;
  762.         boolean oldValueAutoCommit = false;
  763.         boolean rollback = false;
  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.        
  776.             // ISQLQueryObject
  777.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  778.             sqlQueryObject.setANDLogicOperator(true);
  779.             // Connection sql
  780.             connection = this.jdbcServiceManager.getConnection();

  781.             // transaction
  782.             if(this.jdbcProperties.isAutomaticTransactionManagement()){
  783.                 oldValueAutoCommit = connection.getAutoCommit();
  784.                 connection.setAutoCommit(false);
  785.             }

  786.             return this.serviceCRUD.deleteAll(this.jdbcProperties,this.log,connection,sqlQueryObject,jdbcExpression);
  787.    
  788.         }catch(ServiceException | NotImplementedException e){
  789.             rollback = true;
  790.             this.logError(e); throw e;
  791.         }catch(Exception e){
  792.             rollback = true;
  793.             this.logError(e); throw new ServiceException("DeleteAll(expression) not completed: "+e.getMessage(),e);
  794.         }finally{
  795.             this.releaseResources(rollback, connection, oldValueAutoCommit);
  796.         }
  797.    
  798.     }
  799.    
  800.     // -- DB
  801.    
  802.     @Override
  803.     public void deleteById(long tableId) throws ServiceException, NotImplementedException {
  804.        
  805.         Connection connection = null;
  806.         boolean oldValueAutoCommit = false;
  807.         boolean rollback = false;
  808.         try{
  809.            
  810.             // check parameters
  811.             if(tableId<=0){
  812.                 throw new ServiceException("Parameter 'tableId' is less equals 0");
  813.             }
  814.        
  815.             // ISQLQueryObject
  816.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  817.             sqlQueryObject.setANDLogicOperator(true);
  818.             // Connection sql
  819.             connection = this.jdbcServiceManager.getConnection();

  820.             // transaction
  821.             if(this.jdbcProperties.isAutomaticTransactionManagement()){
  822.                 oldValueAutoCommit = connection.getAutoCommit();
  823.                 connection.setAutoCommit(false);
  824.             }

  825.             this.serviceCRUD.deleteById(this.jdbcProperties,this.log,connection,sqlQueryObject,tableId);
  826.    
  827.         }catch(ServiceException | NotImplementedException e){
  828.             rollback = true;
  829.             this.logError(e); throw e;
  830.         }catch(Exception e){
  831.             rollback = true;
  832.             this.logError(e); throw new ServiceException("DeleteById(tableId) not completed: "+e.getMessage(),e);
  833.         }finally{
  834.             this.releaseResources(rollback, connection, oldValueAutoCommit);
  835.         }
  836.    
  837.     }
  838.    
  839.     @Override
  840.     public int nativeUpdate(String sql,Object ... param) throws ServiceException, NotImplementedException {
  841.        
  842.         Connection connection = null;
  843.         boolean oldValueAutoCommit = false;
  844.         boolean rollback = false;
  845.         try{
  846.            
  847.             // check parameters
  848.             if(sql==null){
  849.                 throw new ServiceException("Parameter 'sql' is null");
  850.             }
  851.        
  852.             // ISQLQueryObject
  853.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  854.             sqlQueryObject.setANDLogicOperator(true);
  855.             // Connection sql
  856.             connection = this.jdbcServiceManager.getConnection();

  857.             // transaction
  858.             if(this.jdbcProperties.isAutomaticTransactionManagement()){
  859.                 oldValueAutoCommit = connection.getAutoCommit();
  860.                 connection.setAutoCommit(false);
  861.             }

  862.             return this.serviceCRUD.nativeUpdate(this.jdbcProperties,this.log,connection,sqlQueryObject,sql,param);
  863.    
  864.         }catch(ServiceException | NotImplementedException e){
  865.             rollback = true;
  866.             this.logError(e); throw e;
  867.         }catch(Exception e){
  868.             rollback = true;
  869.             this.logError(e); throw new ServiceException("DeleteById(tableId) not completed: "+e.getMessage(),e);
  870.         }finally{
  871.             this.releaseResources(rollback, connection, oldValueAutoCommit);
  872.         }
  873.    
  874.     }
  875.    
  876. }