JDBCConfigurazionePolicyServiceImpl.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.controllo_traffico.dao.jdbc;

  21. import java.sql.Connection;

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

  23. import org.slf4j.Logger;

  24. import org.openspcoop2.generic_project.dao.jdbc.IJDBCServiceCRUDWithId;
  25. import org.openspcoop2.generic_project.beans.NonNegativeNumber;
  26. import org.openspcoop2.generic_project.beans.UpdateField;
  27. import org.openspcoop2.generic_project.beans.UpdateModel;

  28. import org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities;
  29. import org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject;
  30. import org.openspcoop2.generic_project.exception.NotFoundException;
  31. import org.openspcoop2.generic_project.exception.NotImplementedException;
  32. import org.openspcoop2.generic_project.exception.ServiceException;
  33. import org.openspcoop2.generic_project.expression.IExpression;
  34. import org.openspcoop2.generic_project.dao.jdbc.JDBCExpression;
  35. import org.openspcoop2.generic_project.dao.jdbc.JDBCPaginatedExpression;

  36. import org.openspcoop2.generic_project.dao.jdbc.JDBCServiceManagerProperties;
  37. import org.openspcoop2.core.controllo_traffico.ConfigurazionePolicy;
  38. import org.openspcoop2.core.controllo_traffico.IdPolicy;

  39. /**    
  40.  * JDBCConfigurazionePolicyServiceImpl
  41.  *
  42.  * @author Poli Andrea (poli@link.it)
  43.  * @author $Author$
  44.  * @version $Rev$, $Date$
  45.  */
  46. public class JDBCConfigurazionePolicyServiceImpl extends JDBCConfigurazionePolicyServiceSearchImpl
  47.     implements IJDBCServiceCRUDWithId<ConfigurazionePolicy, IdPolicy, JDBCServiceManager> {

  48.     @Override
  49.     public void create(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, ConfigurazionePolicy configurazionePolicy, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotImplementedException,ServiceException,Exception {

  50.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  51.                 new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);
  52.        
  53.         ISQLQueryObject sqlQueryObjectInsert = sqlQueryObject.newSQLQueryObject();
  54.                


  55.         // Object configurazionePolicy
  56.         sqlQueryObjectInsert.addInsertTable(this.getConfigurazionePolicyFieldConverter().toTable(ConfigurazionePolicy.model()));
  57.         sqlQueryObjectInsert.addInsertField(this.getConfigurazionePolicyFieldConverter().toColumn(ConfigurazionePolicy.model().ID_POLICY,false),"?");
  58.         sqlQueryObjectInsert.addInsertField(this.getConfigurazionePolicyFieldConverter().toColumn(ConfigurazionePolicy.model().BUILT_IN,false),"?");
  59.         sqlQueryObjectInsert.addInsertField(this.getConfigurazionePolicyFieldConverter().toColumn(ConfigurazionePolicy.model().DESCRIZIONE,false),"?");
  60.         sqlQueryObjectInsert.addInsertField(this.getConfigurazionePolicyFieldConverter().toColumn(ConfigurazionePolicy.model().RISORSA,false),"?");
  61.         sqlQueryObjectInsert.addInsertField(this.getConfigurazionePolicyFieldConverter().toColumn(ConfigurazionePolicy.model().SIMULTANEE,false),"?");
  62.         sqlQueryObjectInsert.addInsertField(this.getConfigurazionePolicyFieldConverter().toColumn(ConfigurazionePolicy.model().VALORE,false),"?");
  63.         sqlQueryObjectInsert.addInsertField(this.getConfigurazionePolicyFieldConverter().toColumn(ConfigurazionePolicy.model().VALORE_2,false),"?");
  64.         sqlQueryObjectInsert.addInsertField(this.getConfigurazionePolicyFieldConverter().toColumn(ConfigurazionePolicy.model().VALORE_TIPO_BANDA,false),"?");
  65.         sqlQueryObjectInsert.addInsertField(this.getConfigurazionePolicyFieldConverter().toColumn(ConfigurazionePolicy.model().VALORE_TIPO_LATENZA,false),"?");
  66.         sqlQueryObjectInsert.addInsertField(this.getConfigurazionePolicyFieldConverter().toColumn(ConfigurazionePolicy.model().MODALITA_CONTROLLO,false),"?");
  67.         sqlQueryObjectInsert.addInsertField(this.getConfigurazionePolicyFieldConverter().toColumn(ConfigurazionePolicy.model().TIPO_INTERVALLO_OSSERVAZIONE_REALTIME,false),"?");
  68.         sqlQueryObjectInsert.addInsertField(this.getConfigurazionePolicyFieldConverter().toColumn(ConfigurazionePolicy.model().TIPO_INTERVALLO_OSSERVAZIONE_STATISTICO,false),"?");
  69.         sqlQueryObjectInsert.addInsertField(this.getConfigurazionePolicyFieldConverter().toColumn(ConfigurazionePolicy.model().INTERVALLO_OSSERVAZIONE,false),"?");
  70.         sqlQueryObjectInsert.addInsertField(this.getConfigurazionePolicyFieldConverter().toColumn(ConfigurazionePolicy.model().FINESTRA_OSSERVAZIONE,false),"?");
  71.         sqlQueryObjectInsert.addInsertField(this.getConfigurazionePolicyFieldConverter().toColumn(ConfigurazionePolicy.model().TIPO_APPLICABILITA,false),"?");
  72.         sqlQueryObjectInsert.addInsertField(this.getConfigurazionePolicyFieldConverter().toColumn(ConfigurazionePolicy.model().APPLICABILITA_CON_CONGESTIONE,false),"?");
  73.         sqlQueryObjectInsert.addInsertField(this.getConfigurazionePolicyFieldConverter().toColumn(ConfigurazionePolicy.model().APPLICABILITA_DEGRADO_PRESTAZIONALE,false),"?");
  74.         sqlQueryObjectInsert.addInsertField(this.getConfigurazionePolicyFieldConverter().toColumn(ConfigurazionePolicy.model().DEGRADO_AVG_TIME_MODALITA_CONTROLLO,false),"?");
  75.         sqlQueryObjectInsert.addInsertField(this.getConfigurazionePolicyFieldConverter().toColumn(ConfigurazionePolicy.model().DEGRADO_AVG_TIME_TIPO_INTERVALLO_OSSERVAZIONE_REALTIME,false),"?");
  76.         sqlQueryObjectInsert.addInsertField(this.getConfigurazionePolicyFieldConverter().toColumn(ConfigurazionePolicy.model().DEGRADO_AVG_TIME_TIPO_INTERVALLO_OSSERVAZIONE_STATISTICO,false),"?");
  77.         sqlQueryObjectInsert.addInsertField(this.getConfigurazionePolicyFieldConverter().toColumn(ConfigurazionePolicy.model().DEGRADO_AVG_TIME_INTERVALLO_OSSERVAZIONE,false),"?");
  78.         sqlQueryObjectInsert.addInsertField(this.getConfigurazionePolicyFieldConverter().toColumn(ConfigurazionePolicy.model().DEGRADO_AVG_TIME_FINESTRA_OSSERVAZIONE,false),"?");
  79.         sqlQueryObjectInsert.addInsertField(this.getConfigurazionePolicyFieldConverter().toColumn(ConfigurazionePolicy.model().DEGRADO_AVG_TIME_TIPO_LATENZA,false),"?");
  80.         sqlQueryObjectInsert.addInsertField(this.getConfigurazionePolicyFieldConverter().toColumn(ConfigurazionePolicy.model().APPLICABILITA_STATO_ALLARME,false),"?");
  81.         sqlQueryObjectInsert.addInsertField(this.getConfigurazionePolicyFieldConverter().toColumn(ConfigurazionePolicy.model().ALLARME_NOME,false),"?");
  82.         sqlQueryObjectInsert.addInsertField(this.getConfigurazionePolicyFieldConverter().toColumn(ConfigurazionePolicy.model().ALLARME_STATO,false),"?");
  83.         sqlQueryObjectInsert.addInsertField(this.getConfigurazionePolicyFieldConverter().toColumn(ConfigurazionePolicy.model().ALLARME_NOT_STATO,false),"?");

  84.         // Insert configurazionePolicy
  85.         org.openspcoop2.utils.jdbc.IKeyGeneratorObject keyGenerator = this.getConfigurazionePolicyFetch().getKeyGeneratorObject(ConfigurazionePolicy.model());
  86.         long id = jdbcUtilities.insertAndReturnGeneratedKey(sqlQueryObjectInsert, keyGenerator, jdbcProperties.isShowSql(),
  87.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(configurazionePolicy.getIdPolicy(),ConfigurazionePolicy.model().ID_POLICY.getFieldType()),
  88.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(configurazionePolicy.getBuiltIn(),ConfigurazionePolicy.model().BUILT_IN.getFieldType()),
  89.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(configurazionePolicy.getDescrizione(),ConfigurazionePolicy.model().DESCRIZIONE.getFieldType()),
  90.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(configurazionePolicy.getRisorsa(),ConfigurazionePolicy.model().RISORSA.getFieldType()),
  91.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(configurazionePolicy.getSimultanee(),ConfigurazionePolicy.model().SIMULTANEE.getFieldType()),
  92.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(configurazionePolicy.getValore(),ConfigurazionePolicy.model().VALORE.getFieldType()),
  93.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(configurazionePolicy.getValore2(),ConfigurazionePolicy.model().VALORE_2.getFieldType()),
  94.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(configurazionePolicy.getValoreTipoBanda(),ConfigurazionePolicy.model().VALORE_TIPO_BANDA.getFieldType()),
  95.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(configurazionePolicy.getValoreTipoLatenza(),ConfigurazionePolicy.model().VALORE_TIPO_LATENZA.getFieldType()),
  96.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(configurazionePolicy.getModalitaControllo(),ConfigurazionePolicy.model().MODALITA_CONTROLLO.getFieldType()),
  97.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(configurazionePolicy.getTipoIntervalloOsservazioneRealtime(),ConfigurazionePolicy.model().TIPO_INTERVALLO_OSSERVAZIONE_REALTIME.getFieldType()),
  98.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(configurazionePolicy.getTipoIntervalloOsservazioneStatistico(),ConfigurazionePolicy.model().TIPO_INTERVALLO_OSSERVAZIONE_STATISTICO.getFieldType()),
  99.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(configurazionePolicy.getIntervalloOsservazione(),ConfigurazionePolicy.model().INTERVALLO_OSSERVAZIONE.getFieldType()),
  100.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(configurazionePolicy.getFinestraOsservazione(),ConfigurazionePolicy.model().FINESTRA_OSSERVAZIONE.getFieldType()),
  101.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(configurazionePolicy.getTipoApplicabilita(),ConfigurazionePolicy.model().TIPO_APPLICABILITA.getFieldType()),
  102.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(configurazionePolicy.getApplicabilitaConCongestione(),ConfigurazionePolicy.model().APPLICABILITA_CON_CONGESTIONE.getFieldType()),
  103.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(configurazionePolicy.getApplicabilitaDegradoPrestazionale(),ConfigurazionePolicy.model().APPLICABILITA_DEGRADO_PRESTAZIONALE.getFieldType()),
  104.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(configurazionePolicy.getDegradoAvgTimeModalitaControllo(),ConfigurazionePolicy.model().DEGRADO_AVG_TIME_MODALITA_CONTROLLO.getFieldType()),
  105.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(configurazionePolicy.getDegradoAvgTimeTipoIntervalloOsservazioneRealtime(),ConfigurazionePolicy.model().DEGRADO_AVG_TIME_TIPO_INTERVALLO_OSSERVAZIONE_REALTIME.getFieldType()),
  106.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(configurazionePolicy.getDegradoAvgTimeTipoIntervalloOsservazioneStatistico(),ConfigurazionePolicy.model().DEGRADO_AVG_TIME_TIPO_INTERVALLO_OSSERVAZIONE_STATISTICO.getFieldType()),
  107.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(configurazionePolicy.getDegradoAvgTimeIntervalloOsservazione(),ConfigurazionePolicy.model().DEGRADO_AVG_TIME_INTERVALLO_OSSERVAZIONE.getFieldType()),
  108.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(configurazionePolicy.getDegradoAvgTimeFinestraOsservazione(),ConfigurazionePolicy.model().DEGRADO_AVG_TIME_FINESTRA_OSSERVAZIONE.getFieldType()),
  109.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(configurazionePolicy.getDegradoAvgTimeTipoLatenza(),ConfigurazionePolicy.model().DEGRADO_AVG_TIME_TIPO_LATENZA.getFieldType()),
  110.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(configurazionePolicy.getApplicabilitaStatoAllarme(),ConfigurazionePolicy.model().APPLICABILITA_STATO_ALLARME.getFieldType()),
  111.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(configurazionePolicy.getAllarmeNome(),ConfigurazionePolicy.model().ALLARME_NOME.getFieldType()),
  112.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(configurazionePolicy.getAllarmeStato(),ConfigurazionePolicy.model().ALLARME_STATO.getFieldType()),
  113.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(configurazionePolicy.getAllarmeNotStato(),ConfigurazionePolicy.model().ALLARME_NOT_STATO.getFieldType())
  114.         );
  115.         configurazionePolicy.setId(id);

  116.        
  117.     }

  118.     @Override
  119.     public void update(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdPolicy oldId, ConfigurazionePolicy configurazionePolicy, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotFoundException, NotImplementedException, ServiceException, Exception {
  120.         ISQLQueryObject sqlQueryObjectUpdate = sqlQueryObject.newSQLQueryObject();
  121.         Long longIdByLogicId = this.findIdConfigurazionePolicy(jdbcProperties, log, connection, sqlQueryObjectUpdate.newSQLQueryObject(), oldId, true);
  122.         Long tableId = configurazionePolicy.getId();
  123.         if(tableId != null && tableId.longValue() > 0) {
  124.             if(tableId.longValue() != longIdByLogicId.longValue()) {
  125.                 throw new Exception("Ambiguous parameter: configurazionePolicy.id ["+tableId+"] does not match logic id ["+longIdByLogicId+"]");
  126.             }
  127.         } else {
  128.             tableId = longIdByLogicId;
  129.             configurazionePolicy.setId(tableId);
  130.         }
  131.         if(tableId==null || tableId<=0){
  132.             throw new Exception("Retrieve tableId failed");
  133.         }

  134.         this.update(jdbcProperties, log, connection, sqlQueryObject, tableId, configurazionePolicy, idMappingResolutionBehaviour);
  135.     }
  136.     @Override
  137.     public void update(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId, ConfigurazionePolicy configurazionePolicy, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotFoundException, NotImplementedException, ServiceException, Exception {
  138.    
  139.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  140.                 new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);
  141.        
  142.         ISQLQueryObject sqlQueryObjectInsert = sqlQueryObject.newSQLQueryObject();
  143.         ISQLQueryObject sqlQueryObjectDelete = sqlQueryObjectInsert.newSQLQueryObject();
  144.         ISQLQueryObject sqlQueryObjectGet = sqlQueryObjectDelete.newSQLQueryObject();
  145.         ISQLQueryObject sqlQueryObjectUpdate = sqlQueryObjectGet.newSQLQueryObject();
  146.        


  147.         // Object configurazionePolicy
  148.         sqlQueryObjectUpdate.setANDLogicOperator(true);
  149.         sqlQueryObjectUpdate.addUpdateTable(this.getConfigurazionePolicyFieldConverter().toTable(ConfigurazionePolicy.model()));
  150.         boolean isUpdate = true;
  151.         java.util.List<JDBCObject> lstObjects = new java.util.ArrayList<>();
  152.         sqlQueryObjectUpdate.addUpdateField(this.getConfigurazionePolicyFieldConverter().toColumn(ConfigurazionePolicy.model().ID_POLICY,false), "?");
  153.         lstObjects.add(new JDBCObject(configurazionePolicy.getIdPolicy(), ConfigurazionePolicy.model().ID_POLICY.getFieldType()));
  154.         sqlQueryObjectUpdate.addUpdateField(this.getConfigurazionePolicyFieldConverter().toColumn(ConfigurazionePolicy.model().BUILT_IN,false), "?");
  155.         lstObjects.add(new JDBCObject(configurazionePolicy.getBuiltIn(), ConfigurazionePolicy.model().BUILT_IN.getFieldType()));
  156.         sqlQueryObjectUpdate.addUpdateField(this.getConfigurazionePolicyFieldConverter().toColumn(ConfigurazionePolicy.model().DESCRIZIONE,false), "?");
  157.         lstObjects.add(new JDBCObject(configurazionePolicy.getDescrizione(), ConfigurazionePolicy.model().DESCRIZIONE.getFieldType()));
  158.         sqlQueryObjectUpdate.addUpdateField(this.getConfigurazionePolicyFieldConverter().toColumn(ConfigurazionePolicy.model().RISORSA,false), "?");
  159.         lstObjects.add(new JDBCObject(configurazionePolicy.getRisorsa(), ConfigurazionePolicy.model().RISORSA.getFieldType()));
  160.         sqlQueryObjectUpdate.addUpdateField(this.getConfigurazionePolicyFieldConverter().toColumn(ConfigurazionePolicy.model().SIMULTANEE,false), "?");
  161.         lstObjects.add(new JDBCObject(configurazionePolicy.getSimultanee(), ConfigurazionePolicy.model().SIMULTANEE.getFieldType()));
  162.         sqlQueryObjectUpdate.addUpdateField(this.getConfigurazionePolicyFieldConverter().toColumn(ConfigurazionePolicy.model().VALORE,false), "?");
  163.         lstObjects.add(new JDBCObject(configurazionePolicy.getValore(), ConfigurazionePolicy.model().VALORE.getFieldType()));
  164.         sqlQueryObjectUpdate.addUpdateField(this.getConfigurazionePolicyFieldConverter().toColumn(ConfigurazionePolicy.model().VALORE_2,false), "?");
  165.         lstObjects.add(new JDBCObject(configurazionePolicy.getValore2(), ConfigurazionePolicy.model().VALORE_2.getFieldType()));
  166.         sqlQueryObjectUpdate.addUpdateField(this.getConfigurazionePolicyFieldConverter().toColumn(ConfigurazionePolicy.model().VALORE_TIPO_BANDA,false), "?");
  167.         lstObjects.add(new JDBCObject(configurazionePolicy.getValoreTipoBanda(), ConfigurazionePolicy.model().VALORE_TIPO_BANDA.getFieldType()));
  168.         sqlQueryObjectUpdate.addUpdateField(this.getConfigurazionePolicyFieldConverter().toColumn(ConfigurazionePolicy.model().VALORE_TIPO_LATENZA,false), "?");
  169.         lstObjects.add(new JDBCObject(configurazionePolicy.getValoreTipoLatenza(), ConfigurazionePolicy.model().VALORE_TIPO_LATENZA.getFieldType()));
  170.         sqlQueryObjectUpdate.addUpdateField(this.getConfigurazionePolicyFieldConverter().toColumn(ConfigurazionePolicy.model().MODALITA_CONTROLLO,false), "?");
  171.         lstObjects.add(new JDBCObject(configurazionePolicy.getModalitaControllo(), ConfigurazionePolicy.model().MODALITA_CONTROLLO.getFieldType()));
  172.         sqlQueryObjectUpdate.addUpdateField(this.getConfigurazionePolicyFieldConverter().toColumn(ConfigurazionePolicy.model().TIPO_INTERVALLO_OSSERVAZIONE_REALTIME,false), "?");
  173.         lstObjects.add(new JDBCObject(configurazionePolicy.getTipoIntervalloOsservazioneRealtime(), ConfigurazionePolicy.model().TIPO_INTERVALLO_OSSERVAZIONE_REALTIME.getFieldType()));
  174.         sqlQueryObjectUpdate.addUpdateField(this.getConfigurazionePolicyFieldConverter().toColumn(ConfigurazionePolicy.model().TIPO_INTERVALLO_OSSERVAZIONE_STATISTICO,false), "?");
  175.         lstObjects.add(new JDBCObject(configurazionePolicy.getTipoIntervalloOsservazioneStatistico(), ConfigurazionePolicy.model().TIPO_INTERVALLO_OSSERVAZIONE_STATISTICO.getFieldType()));
  176.         sqlQueryObjectUpdate.addUpdateField(this.getConfigurazionePolicyFieldConverter().toColumn(ConfigurazionePolicy.model().INTERVALLO_OSSERVAZIONE,false), "?");
  177.         lstObjects.add(new JDBCObject(configurazionePolicy.getIntervalloOsservazione(), ConfigurazionePolicy.model().INTERVALLO_OSSERVAZIONE.getFieldType()));
  178.         sqlQueryObjectUpdate.addUpdateField(this.getConfigurazionePolicyFieldConverter().toColumn(ConfigurazionePolicy.model().FINESTRA_OSSERVAZIONE,false), "?");
  179.         lstObjects.add(new JDBCObject(configurazionePolicy.getFinestraOsservazione(), ConfigurazionePolicy.model().FINESTRA_OSSERVAZIONE.getFieldType()));
  180.         sqlQueryObjectUpdate.addUpdateField(this.getConfigurazionePolicyFieldConverter().toColumn(ConfigurazionePolicy.model().TIPO_APPLICABILITA,false), "?");
  181.         lstObjects.add(new JDBCObject(configurazionePolicy.getTipoApplicabilita(), ConfigurazionePolicy.model().TIPO_APPLICABILITA.getFieldType()));
  182.         sqlQueryObjectUpdate.addUpdateField(this.getConfigurazionePolicyFieldConverter().toColumn(ConfigurazionePolicy.model().APPLICABILITA_CON_CONGESTIONE,false), "?");
  183.         lstObjects.add(new JDBCObject(configurazionePolicy.getApplicabilitaConCongestione(), ConfigurazionePolicy.model().APPLICABILITA_CON_CONGESTIONE.getFieldType()));
  184.         sqlQueryObjectUpdate.addUpdateField(this.getConfigurazionePolicyFieldConverter().toColumn(ConfigurazionePolicy.model().APPLICABILITA_DEGRADO_PRESTAZIONALE,false), "?");
  185.         lstObjects.add(new JDBCObject(configurazionePolicy.getApplicabilitaDegradoPrestazionale(), ConfigurazionePolicy.model().APPLICABILITA_DEGRADO_PRESTAZIONALE.getFieldType()));
  186.         sqlQueryObjectUpdate.addUpdateField(this.getConfigurazionePolicyFieldConverter().toColumn(ConfigurazionePolicy.model().DEGRADO_AVG_TIME_MODALITA_CONTROLLO,false), "?");
  187.         lstObjects.add(new JDBCObject(configurazionePolicy.getDegradoAvgTimeModalitaControllo(), ConfigurazionePolicy.model().DEGRADO_AVG_TIME_MODALITA_CONTROLLO.getFieldType()));
  188.         sqlQueryObjectUpdate.addUpdateField(this.getConfigurazionePolicyFieldConverter().toColumn(ConfigurazionePolicy.model().DEGRADO_AVG_TIME_TIPO_INTERVALLO_OSSERVAZIONE_REALTIME,false), "?");
  189.         lstObjects.add(new JDBCObject(configurazionePolicy.getDegradoAvgTimeTipoIntervalloOsservazioneRealtime(), ConfigurazionePolicy.model().DEGRADO_AVG_TIME_TIPO_INTERVALLO_OSSERVAZIONE_REALTIME.getFieldType()));
  190.         sqlQueryObjectUpdate.addUpdateField(this.getConfigurazionePolicyFieldConverter().toColumn(ConfigurazionePolicy.model().DEGRADO_AVG_TIME_TIPO_INTERVALLO_OSSERVAZIONE_STATISTICO,false), "?");
  191.         lstObjects.add(new JDBCObject(configurazionePolicy.getDegradoAvgTimeTipoIntervalloOsservazioneStatistico(), ConfigurazionePolicy.model().DEGRADO_AVG_TIME_TIPO_INTERVALLO_OSSERVAZIONE_STATISTICO.getFieldType()));
  192.         sqlQueryObjectUpdate.addUpdateField(this.getConfigurazionePolicyFieldConverter().toColumn(ConfigurazionePolicy.model().DEGRADO_AVG_TIME_INTERVALLO_OSSERVAZIONE,false), "?");
  193.         lstObjects.add(new JDBCObject(configurazionePolicy.getDegradoAvgTimeIntervalloOsservazione(), ConfigurazionePolicy.model().DEGRADO_AVG_TIME_INTERVALLO_OSSERVAZIONE.getFieldType()));
  194.         sqlQueryObjectUpdate.addUpdateField(this.getConfigurazionePolicyFieldConverter().toColumn(ConfigurazionePolicy.model().DEGRADO_AVG_TIME_FINESTRA_OSSERVAZIONE,false), "?");
  195.         lstObjects.add(new JDBCObject(configurazionePolicy.getDegradoAvgTimeFinestraOsservazione(), ConfigurazionePolicy.model().DEGRADO_AVG_TIME_FINESTRA_OSSERVAZIONE.getFieldType()));
  196.         sqlQueryObjectUpdate.addUpdateField(this.getConfigurazionePolicyFieldConverter().toColumn(ConfigurazionePolicy.model().DEGRADO_AVG_TIME_TIPO_LATENZA,false), "?");
  197.         lstObjects.add(new JDBCObject(configurazionePolicy.getDegradoAvgTimeTipoLatenza(), ConfigurazionePolicy.model().DEGRADO_AVG_TIME_TIPO_LATENZA.getFieldType()));
  198.         sqlQueryObjectUpdate.addUpdateField(this.getConfigurazionePolicyFieldConverter().toColumn(ConfigurazionePolicy.model().APPLICABILITA_STATO_ALLARME,false), "?");
  199.         lstObjects.add(new JDBCObject(configurazionePolicy.getApplicabilitaStatoAllarme(), ConfigurazionePolicy.model().APPLICABILITA_STATO_ALLARME.getFieldType()));
  200.         sqlQueryObjectUpdate.addUpdateField(this.getConfigurazionePolicyFieldConverter().toColumn(ConfigurazionePolicy.model().ALLARME_NOME,false), "?");
  201.         lstObjects.add(new JDBCObject(configurazionePolicy.getAllarmeNome(), ConfigurazionePolicy.model().ALLARME_NOME.getFieldType()));
  202.         sqlQueryObjectUpdate.addUpdateField(this.getConfigurazionePolicyFieldConverter().toColumn(ConfigurazionePolicy.model().ALLARME_STATO,false), "?");
  203.         lstObjects.add(new JDBCObject(configurazionePolicy.getAllarmeStato(), ConfigurazionePolicy.model().ALLARME_STATO.getFieldType()));
  204.         sqlQueryObjectUpdate.addUpdateField(this.getConfigurazionePolicyFieldConverter().toColumn(ConfigurazionePolicy.model().ALLARME_NOT_STATO,false), "?");
  205.         lstObjects.add(new JDBCObject(configurazionePolicy.getAllarmeNotStato(), ConfigurazionePolicy.model().ALLARME_NOT_STATO.getFieldType()));
  206.         sqlQueryObjectUpdate.addWhereCondition("id=?");
  207.         lstObjects.add(new JDBCObject(tableId, Long.class));

  208.         if(isUpdate) {
  209.             // Update configurazionePolicy
  210.             jdbcUtilities.executeUpdate(sqlQueryObjectUpdate.createSQLUpdate(), jdbcProperties.isShowSql(),
  211.                 lstObjects.toArray(new JDBCObject[]{}));
  212.         }


  213.     }
  214.    
  215.     @Override
  216.     public void updateFields(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdPolicy id, UpdateField ... updateFields) throws NotFoundException, NotImplementedException, ServiceException, Exception {
  217.        
  218.         GenericJDBCUtilities.updateFields(jdbcProperties, log, connection, sqlQueryObject,
  219.                 this.getConfigurazionePolicyFieldConverter().toTable(ConfigurazionePolicy.model()),
  220.                 this.getMapTableToPKColumnEngine(),
  221.                 this.getRootTablePrimaryKeyValuesEngine(jdbcProperties, log, connection, sqlQueryObject, id),
  222.                 this.getConfigurazionePolicyFieldConverter(), this, null, updateFields);
  223.     }
  224.    
  225.     @Override
  226.     public void updateFields(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdPolicy id, IExpression condition, UpdateField ... updateFields) throws NotFoundException, NotImplementedException, ServiceException, Exception {
  227.        
  228.         GenericJDBCUtilities.updateFields(jdbcProperties, log, connection, sqlQueryObject,
  229.                 this.getConfigurazionePolicyFieldConverter().toTable(ConfigurazionePolicy.model()),
  230.                 this.getMapTableToPKColumnEngine(),
  231.                 this.getRootTablePrimaryKeyValuesEngine(jdbcProperties, log, connection, sqlQueryObject, id),
  232.                 this.getConfigurazionePolicyFieldConverter(), this, condition, updateFields);
  233.     }
  234.    
  235.     @Override
  236.     public void updateFields(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdPolicy id, UpdateModel ... updateModels) throws NotFoundException, NotImplementedException, ServiceException, Exception {
  237.        
  238.         GenericJDBCUtilities.updateFields(jdbcProperties, log, connection, sqlQueryObject,
  239.                 this.getConfigurazionePolicyFieldConverter().toTable(ConfigurazionePolicy.model()),
  240.                 this.getMapTableToPKColumnEngine(),
  241.                 this.getRootTablePrimaryKeyValuesEngine(jdbcProperties, log, connection, sqlQueryObject, id),
  242.                 this.getConfigurazionePolicyFieldConverter(), this, updateModels);
  243.     }  
  244.    
  245.     @Override
  246.     public void updateFields(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId, UpdateField ... updateFields) throws NotFoundException, NotImplementedException, ServiceException, Exception {
  247.         java.util.List<Object> ids = new java.util.ArrayList<>();
  248.         ids.add(tableId);
  249.         GenericJDBCUtilities.updateFields(jdbcProperties, log, connection, sqlQueryObject,
  250.                 this.getConfigurazionePolicyFieldConverter().toTable(ConfigurazionePolicy.model()),
  251.                 this.getMapTableToPKColumnEngine(),
  252.                 ids,
  253.                 this.getConfigurazionePolicyFieldConverter(), this, null, updateFields);
  254.     }
  255.    
  256.     @Override
  257.     public void updateFields(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId, IExpression condition, UpdateField ... updateFields) throws NotFoundException, NotImplementedException, ServiceException, Exception {
  258.         java.util.List<Object> ids = new java.util.ArrayList<>();
  259.         ids.add(tableId);
  260.         GenericJDBCUtilities.updateFields(jdbcProperties, log, connection, sqlQueryObject,
  261.                 this.getConfigurazionePolicyFieldConverter().toTable(ConfigurazionePolicy.model()),
  262.                 this.getMapTableToPKColumnEngine(),
  263.                 ids,
  264.                 this.getConfigurazionePolicyFieldConverter(), this, condition, updateFields);
  265.     }
  266.    
  267.     @Override
  268.     public void updateFields(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId, UpdateModel ... updateModels) throws NotFoundException, NotImplementedException, ServiceException, Exception {
  269.         java.util.List<Object> ids = new java.util.ArrayList<>();
  270.         ids.add(tableId);
  271.         GenericJDBCUtilities.updateFields(jdbcProperties, log, connection, sqlQueryObject,
  272.                 this.getConfigurazionePolicyFieldConverter().toTable(ConfigurazionePolicy.model()),
  273.                 this.getMapTableToPKColumnEngine(),
  274.                 ids,
  275.                 this.getConfigurazionePolicyFieldConverter(), this, updateModels);
  276.     }
  277.    
  278.     @Override
  279.     public void updateOrCreate(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdPolicy oldId, ConfigurazionePolicy configurazionePolicy, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotImplementedException,ServiceException,Exception {
  280.    
  281.         if(this.exists(jdbcProperties, log, connection, sqlQueryObject, oldId)) {
  282.             this.update(jdbcProperties, log, connection, sqlQueryObject, oldId, configurazionePolicy,idMappingResolutionBehaviour);
  283.         } else {
  284.             this.create(jdbcProperties, log, connection, sqlQueryObject, configurazionePolicy,idMappingResolutionBehaviour);
  285.         }
  286.        
  287.     }
  288.    
  289.     @Override
  290.     public void updateOrCreate(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId, ConfigurazionePolicy configurazionePolicy, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotImplementedException,ServiceException,Exception {
  291.         if(this.exists(jdbcProperties, log, connection, sqlQueryObject, tableId)) {
  292.             this.update(jdbcProperties, log, connection, sqlQueryObject, tableId, configurazionePolicy,idMappingResolutionBehaviour);
  293.         } else {
  294.             this.create(jdbcProperties, log, connection, sqlQueryObject, configurazionePolicy,idMappingResolutionBehaviour);
  295.         }
  296.     }
  297.    
  298.     @Override
  299.     public void delete(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, ConfigurazionePolicy configurazionePolicy) throws NotImplementedException,ServiceException,Exception {
  300.        
  301.        
  302.         Long longId = null;
  303.         if( (configurazionePolicy.getId()!=null) && (configurazionePolicy.getId()>0) ){
  304.             longId = configurazionePolicy.getId();
  305.         }
  306.         else{
  307.             IdPolicy idConfigurazionePolicy = this.convertToId(jdbcProperties,log,connection,sqlQueryObject,configurazionePolicy);
  308.             longId = this.findIdConfigurazionePolicy(jdbcProperties,log,connection,sqlQueryObject,idConfigurazionePolicy,false);
  309.             if(longId == null){
  310.                 return; // entry not exists
  311.             }
  312.         }      
  313.        
  314.         this.deleteEngine(jdbcProperties, log, connection, sqlQueryObject, longId);
  315.        
  316.     }

  317.     private void deleteEngine(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, Long id) throws NotImplementedException,ServiceException,Exception {
  318.    
  319.         if(id!=null && id.longValue()<=0){
  320.             throw new ServiceException("Id is less equals 0");
  321.         }
  322.        
  323.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  324.                 new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);
  325.        
  326.         ISQLQueryObject sqlQueryObjectDelete = sqlQueryObject.newSQLQueryObject();
  327.        

  328.         // Object configurazionePolicy
  329.         sqlQueryObjectDelete.setANDLogicOperator(true);
  330.         sqlQueryObjectDelete.addDeleteTable(this.getConfigurazionePolicyFieldConverter().toTable(ConfigurazionePolicy.model()));
  331.         if(id != null)
  332.             sqlQueryObjectDelete.addWhereCondition("id=?");

  333.         // Delete configurazionePolicy
  334.         jdbcUtilities.execute(sqlQueryObjectDelete.createSQLDelete(), jdbcProperties.isShowSql(),
  335.             new JDBCObject(id,Long.class));

  336.     }

  337.     @Override
  338.     public void deleteById(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdPolicy idConfigurazionePolicy) throws NotImplementedException,ServiceException,Exception {

  339.         Long id = null;
  340.         try{
  341.             id = this.findIdConfigurazionePolicy(jdbcProperties, log, connection, sqlQueryObject, idConfigurazionePolicy, true);
  342.         }catch(NotFoundException notFound){
  343.             return;
  344.         }
  345.         this.deleteEngine(jdbcProperties, log, connection, sqlQueryObject, id);
  346.        
  347.     }
  348.    
  349.     @Override
  350.     public NonNegativeNumber deleteAll(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject) throws NotImplementedException,ServiceException,Exception {
  351.        
  352.         return this.deleteAll(jdbcProperties, log, connection, sqlQueryObject, new JDBCExpression(this.getConfigurazionePolicyFieldConverter()));

  353.     }

  354.     @Override
  355.     public NonNegativeNumber deleteAll(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCExpression expression) throws NotImplementedException, ServiceException,Exception {

  356.         java.util.List<Long> lst = this.findAllTableIds(jdbcProperties, log, connection, sqlQueryObject, new JDBCPaginatedExpression(expression));
  357.        
  358.         for(Long id : lst) {
  359.             this.deleteEngine(jdbcProperties, log, connection, sqlQueryObject, id);
  360.         }
  361.        
  362.         return new NonNegativeNumber(lst.size());
  363.    
  364.     }



  365.     // -- DB
  366.    
  367.     @Override
  368.     public void deleteById(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId) throws ServiceException, NotImplementedException, Exception {
  369.         this.deleteEngine(jdbcProperties, log, connection, sqlQueryObject, Long.valueOf(tableId));
  370.     }
  371.    
  372.     @Override
  373.     public int nativeUpdate(JDBCServiceManagerProperties jdbcProperties, Logger log,Connection connection,ISQLQueryObject sqlObject, String sql,Object ... param) throws ServiceException,NotImplementedException, Exception {
  374.    
  375.         return org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.nativeUpdate(jdbcProperties, log, connection, sqlObject,
  376.                                                                                             sql,param);
  377.    
  378.     }
  379. }