JDBCStatisticaInfoService.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.StatisticaInfo;
  33. import org.openspcoop2.core.statistiche.dao.IDBStatisticaInfoService;
  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.StatisticaInfo}
  39.  *
  40.  * @author Poli Andrea (poli@link.it)
  41.  * @author Tommaso Burlon (tommaso.burlon@link.it)
  42.  * @author $Author$
  43.  * @version $Rev$, $Date$
  44.  */

  45. public class JDBCStatisticaInfoService extends JDBCStatisticaInfoServiceSearch  implements IDBStatisticaInfoService {


  46.     private IJDBCServiceCRUDWithoutId<StatisticaInfo, JDBCServiceManager> serviceCRUD = null;
  47.     public JDBCStatisticaInfoService(JDBCServiceManager jdbcServiceManager) throws ServiceException {
  48.         super(jdbcServiceManager);
  49.         String msgInit = JDBCStatisticaInfoService.class.getName()+ " initialized";
  50.         this.log.debug(msgInit);
  51.         this.serviceCRUD = JDBCProperties.getInstance(org.openspcoop2.core.statistiche.dao.jdbc.JDBCServiceManager.class.getPackage(),ProjectInfo.getInstance()).getServiceCRUD("statisticaInfo");
  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+StatisticaInfo.class.getName()+") 'statisticaInfo' 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 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(StatisticaInfo statisticaInfo) throws ServiceException, NotImplementedException {
  112.         try{
  113.             this.create(statisticaInfo, 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(StatisticaInfo statisticaInfo, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws ServiceException, NotImplementedException {
  122.         try{
  123.             this.create(statisticaInfo, 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(StatisticaInfo statisticaInfo, boolean validate) throws ServiceException, NotImplementedException, ValidationException {
  132.         this.create(statisticaInfo, validate, null);
  133.     }
  134.    
  135.     @Override
  136.     public void create(StatisticaInfo statisticaInfo, 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(statisticaInfo==null){
  145.                 throw this.newServiceExceptionParameterIsNull();
  146.             }
  147.            
  148.             // validate
  149.             if(validate){
  150.                 this.validate(statisticaInfo);
  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,statisticaInfo,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(StatisticaInfo statisticaInfo) throws ServiceException, NotFoundException, NotImplementedException {
  177.         try{
  178.             this.update(statisticaInfo, 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(StatisticaInfo statisticaInfo, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws ServiceException, NotFoundException, NotImplementedException {
  187.         try{
  188.             this.update(statisticaInfo, 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(StatisticaInfo statisticaInfo, boolean validate) throws ServiceException, NotFoundException, NotImplementedException, ValidationException {
  197.         this.update(statisticaInfo, validate, null);
  198.     }
  199.        
  200.     @Override
  201.     public void update(StatisticaInfo statisticaInfo, 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(statisticaInfo==null){
  210.                 throw this.newServiceExceptionParameterIsNull();
  211.             }

  212.             // validate
  213.             if(validate){
  214.                 this.validate(statisticaInfo);
  215.             }

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

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

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

  283.             // validate
  284.             if(validate){
  285.                 this.validate(statisticaInfo);
  286.             }

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

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

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

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

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

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

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

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

  399.     }

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

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

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

  440.     }

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

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

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

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

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

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

  526.     }

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

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

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

  567.     }

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

  587.     @Override
  588.     public void updateOrCreate(StatisticaInfo statisticaInfo, boolean validate) throws ServiceException, NotImplementedException, ValidationException {
  589.         this.updateOrCreate(statisticaInfo, validate, null);
  590.     }

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

  603.             // validate
  604.             if(validate){
  605.                 this.validate(statisticaInfo);
  606.             }

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

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

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

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

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

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

  668.             // validate
  669.             if(validate){
  670.                 this.validate(statisticaInfo);
  671.             }

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

  683.             this.serviceCRUD.updateOrCreate(this.jdbcProperties,this.log,connection,sqlQueryObject,tableId,statisticaInfo,idMappingResolutionBehaviour);

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

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

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

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

  717.             this.serviceCRUD.delete(this.jdbcProperties,this.log,connection,sqlQueryObject,statisticaInfo);

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


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

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

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

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

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

  759.     @Override
  760.     public NonNegativeNumber deleteAll(IExpression expression) throws ServiceException, NotImplementedException {
  761.        
  762.         Connection connection = null;
  763.         boolean oldValueAutoCommit = false;
  764.         boolean rollback = false;
  765.         try{
  766.            
  767.             // check parameters
  768.             if(expression==null){
  769.                 throw this.newServiceExceptionParameterExpressionIsNull();
  770.             }
  771.             if( ! (expression instanceof JDBCExpression) ){
  772.                 throw this.newServiceExceptionParameterExpressionWrongType(expression);
  773.             }
  774.             JDBCExpression jdbcExpression = (JDBCExpression) expression;
  775.             this.logJDBCExpression(jdbcExpression);
  776.        
  777.             // ISQLQueryObject
  778.             ISQLQueryObject sqlQueryObject = this.jdbcSqlObjectFactory.createSQLQueryObject(this.jdbcProperties.getDatabase());
  779.             sqlQueryObject.setANDLogicOperator(true);
  780.             // Connection sql
  781.             connection = this.jdbcServiceManager.getConnection();

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

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

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

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

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

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