JDBCAllarmeServiceSearchImpl.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.allarmi.dao.jdbc;

  21. import java.sql.Connection;
  22. import java.util.ArrayList;
  23. import java.util.List;
  24. import java.util.Map;

  25. import org.openspcoop2.core.allarmi.Allarme;
  26. import org.openspcoop2.core.allarmi.AllarmeParametro;
  27. import org.openspcoop2.core.allarmi.IdAllarme;
  28. import org.openspcoop2.core.allarmi.constants.RuoloPorta;
  29. import org.openspcoop2.core.allarmi.dao.jdbc.converter.AllarmeFieldConverter;
  30. import org.openspcoop2.core.allarmi.dao.jdbc.fetch.AllarmeFetch;
  31. import org.openspcoop2.generic_project.beans.CustomField;
  32. import org.openspcoop2.generic_project.beans.FunctionField;
  33. import org.openspcoop2.generic_project.beans.IField;
  34. import org.openspcoop2.generic_project.beans.InUse;
  35. import org.openspcoop2.generic_project.beans.NonNegativeNumber;
  36. import org.openspcoop2.generic_project.beans.Union;
  37. import org.openspcoop2.generic_project.beans.UnionExpression;
  38. import org.openspcoop2.generic_project.dao.jdbc.IJDBCServiceSearchWithId;
  39. import org.openspcoop2.generic_project.dao.jdbc.JDBCExpression;
  40. import org.openspcoop2.generic_project.dao.jdbc.JDBCPaginatedExpression;
  41. import org.openspcoop2.generic_project.dao.jdbc.JDBCServiceManagerProperties;
  42. import org.openspcoop2.generic_project.dao.jdbc.utils.IJDBCFetch;
  43. import org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject;
  44. import org.openspcoop2.generic_project.exception.MultipleResultException;
  45. import org.openspcoop2.generic_project.exception.NotFoundException;
  46. import org.openspcoop2.generic_project.exception.NotImplementedException;
  47. import org.openspcoop2.generic_project.exception.ServiceException;
  48. import org.openspcoop2.generic_project.expression.IExpression;
  49. import org.openspcoop2.generic_project.expression.impl.sql.ISQLFieldConverter;
  50. import org.openspcoop2.generic_project.utils.UtilsTemplate;
  51. import org.openspcoop2.utils.sql.ISQLQueryObject;
  52. import org.slf4j.Logger;

  53. /**    
  54.  * JDBCAllarmeServiceSearchImpl
  55.  *
  56.  * @author Poli Andrea (poli@link.it)
  57.  * @author $Author$
  58.  * @version $Rev$, $Date$
  59.  */
  60. public class JDBCAllarmeServiceSearchImpl implements IJDBCServiceSearchWithId<Allarme, IdAllarme, JDBCServiceManager> {

  61.     private AllarmeFieldConverter _allarmeFieldConverter = null;
  62.     public AllarmeFieldConverter getAllarmeFieldConverter() {
  63.         if(this._allarmeFieldConverter==null){
  64.             this._allarmeFieldConverter = new AllarmeFieldConverter(this.jdbcServiceManager.getJdbcProperties().getDatabaseType());
  65.         }      
  66.         return this._allarmeFieldConverter;
  67.     }
  68.     @Override
  69.     public ISQLFieldConverter getFieldConverter() {
  70.         return this.getAllarmeFieldConverter();
  71.     }
  72.    
  73.     private AllarmeFetch allarmeFetch = new AllarmeFetch();
  74.     public AllarmeFetch getAllarmeFetch() {
  75.         return this.allarmeFetch;
  76.     }
  77.     @Override
  78.     public IJDBCFetch getFetch() {
  79.         return getAllarmeFetch();
  80.     }
  81.    
  82.    
  83.     private JDBCServiceManager jdbcServiceManager = null;

  84.     @Override
  85.     public void setServiceManager(JDBCServiceManager serviceManager) throws ServiceException{
  86.         this.jdbcServiceManager = serviceManager;
  87.     }
  88.    
  89.     @Override
  90.     public JDBCServiceManager getServiceManager() throws ServiceException{
  91.         return this.jdbcServiceManager;
  92.     }
  93.    

  94.     @Override
  95.     public IdAllarme convertToId(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, Allarme allarme) throws NotImplementedException, ServiceException, Exception{
  96.    
  97.         IdAllarme idAllarme = new IdAllarme();
  98.         idAllarme.setNome(allarme.getNome());
  99.        
  100.         // opzionali
  101.         idAllarme.setTipo(allarme.getTipo());
  102.         idAllarme.setEnabled(allarme.getEnabled());
  103.         idAllarme.setAlias(allarme.getAlias());
  104.         if(allarme.getFiltro()!=null) {
  105.             idAllarme.setFiltroRuoloPorta(allarme.getFiltro().getRuoloPorta());
  106.             idAllarme.setFiltroNomePorta(allarme.getFiltro().getNomePorta());
  107.         }
  108.        
  109.         return idAllarme;
  110.     }
  111.    
  112.     @Override
  113.     public Allarme get(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdAllarme id, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotFoundException, MultipleResultException, NotImplementedException, ServiceException,Exception {
  114.         Long idAllarme = ( (id!=null && id.getId()!=null && id.getId()>0) ? id.getId() : this.findIdAllarme(jdbcProperties, log, connection, sqlQueryObject, id, true));
  115.         return this.getEngine(jdbcProperties, log, connection, sqlQueryObject, idAllarme,idMappingResolutionBehaviour);
  116.        
  117.        
  118.     }
  119.    
  120.     @Override
  121.     public boolean exists(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdAllarme id) throws MultipleResultException, NotImplementedException, ServiceException,Exception {

  122.         Long idAllarme = this.findIdAllarme(jdbcProperties, log, connection, sqlQueryObject, id, false);
  123.         return idAllarme != null && idAllarme > 0;
  124.        
  125.     }
  126.    
  127.     @Override
  128.     public List<IdAllarme> findAllIds(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCPaginatedExpression expression, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotImplementedException, ServiceException,Exception {

  129.         List<IdAllarme> list = new ArrayList<>();

  130.         // TODO: implementazione non efficiente.
  131.         // Per ottenere una implementazione efficiente:
  132.         // 1. Usare metodo select di questa classe indirizzando esattamente i field necessari a create l'ID logico
  133.         // 2. Usare metodo getAllarmeFetch() sul risultato della select per ottenere un oggetto Allarme
  134.         //    La fetch con la map inserirĂ  nell'oggetto solo i valori estratti
  135.         // 3. Usare metodo convertToId per ottenere l'id

  136.         List<Long> ids = this.findAllTableIds(jdbcProperties, log, connection, sqlQueryObject, expression);
  137.        
  138.         for(Long id: ids) {
  139.             Allarme allarme = this.get(jdbcProperties, log, connection, sqlQueryObject, id, idMappingResolutionBehaviour);
  140.             IdAllarme idAllarme = this.convertToId(jdbcProperties,log,connection,sqlQueryObject,allarme);
  141.             list.add(idAllarme);
  142.         }

  143.         return list;
  144.        
  145.     }
  146.    
  147.     @Override
  148.     public List<Allarme> findAll(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCPaginatedExpression expression, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotImplementedException, ServiceException,Exception {

  149.         List<Allarme> list = new ArrayList<Allarme>();
  150.        
  151.         // TODO: implementazione non efficiente.
  152.         // Per ottenere una implementazione efficiente:
  153.         // 1. Usare metodo select di questa classe indirizzando esattamente i field necessari
  154.         // 2. Usare metodo getAllarmeFetch() sul risultato della select per ottenere un oggetto Allarme
  155.         //    La fetch con la map inserirĂ  nell'oggetto solo i valori estratti

  156.         List<Long> ids = this.findAllTableIds(jdbcProperties, log, connection, sqlQueryObject, expression);
  157.        
  158.         for(Long id: ids) {
  159.             list.add(this.get(jdbcProperties, log, connection, sqlQueryObject, id, idMappingResolutionBehaviour));
  160.         }

  161.         return list;      
  162.        
  163.     }
  164.    
  165.     @Override
  166.     public Allarme find(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCExpression expression, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour)
  167.         throws NotFoundException, MultipleResultException, NotImplementedException, ServiceException,Exception {

  168.         long id = this.findTableId(jdbcProperties, log, connection, sqlQueryObject, expression);
  169.         if(id>0){
  170.             return this.get(jdbcProperties, log, connection, sqlQueryObject, id, idMappingResolutionBehaviour);
  171.         }else{
  172.             throw new NotFoundException("Entry with id["+id+"] not found");
  173.         }
  174.        
  175.     }
  176.    
  177.     @Override
  178.     public NonNegativeNumber count(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCExpression expression) throws NotImplementedException, ServiceException,Exception {
  179.        
  180.         List<Object> listaQuery = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareCount(jdbcProperties, log, connection, sqlQueryObject, expression,
  181.                                                 this.getAllarmeFieldConverter(), Allarme.model());
  182.        
  183.         sqlQueryObject.addSelectCountField(this.getAllarmeFieldConverter().toTable(Allarme.model())+".id","tot",true);
  184.        
  185.         joinEngine(expression,sqlQueryObject);
  186.        
  187.         return org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.count(jdbcProperties, log, connection, sqlQueryObject, expression,
  188.                                                                             this.getAllarmeFieldConverter(), Allarme.model(),listaQuery);
  189.     }

  190.     @Override
  191.     public InUse inUse(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdAllarme id) throws NotFoundException, NotImplementedException, ServiceException,Exception {
  192.        
  193.         Long idAllarme = this.findIdAllarme(jdbcProperties, log, connection, sqlQueryObject, id, true);
  194.         return this.inUseEngine(jdbcProperties, log, connection, sqlQueryObject, idAllarme);
  195.        
  196.     }

  197.     @Override
  198.     public List<Object> select(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  199.                                                     JDBCPaginatedExpression paginatedExpression, IField field) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  200.         return this.select(jdbcProperties, log, connection, sqlQueryObject,
  201.                                 paginatedExpression, false, field);
  202.     }
  203.    
  204.     @Override
  205.     public List<Object> select(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  206.                                                     JDBCPaginatedExpression paginatedExpression, boolean distinct, IField field) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  207.         List<Map<String,Object>> map =
  208.             this.select(jdbcProperties, log, connection, sqlQueryObject, paginatedExpression, distinct, new IField[]{field});
  209.         return org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.selectSingleObject(map);
  210.     }
  211.    
  212.     @Override
  213.     public List<Map<String,Object>> select(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  214.                                                     JDBCPaginatedExpression paginatedExpression, IField ... field) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  215.         return this.select(jdbcProperties, log, connection, sqlQueryObject,
  216.                                 paginatedExpression, false, field);
  217.     }
  218.    
  219.     @Override
  220.     public List<Map<String,Object>> select(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  221.                                                     JDBCPaginatedExpression paginatedExpression, boolean distinct, IField ... field) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  222.        
  223.         org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.setFields(sqlQueryObject,paginatedExpression,field);
  224.         try{
  225.        
  226.             ISQLQueryObject sqlQueryObjectDistinct =
  227.                         org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareSqlQueryObjectForSelectDistinct(distinct,sqlQueryObject, paginatedExpression, log,
  228.                                                 this.getAllarmeFieldConverter(), field);

  229.             return selectEngine(jdbcProperties, log, connection, sqlQueryObject, paginatedExpression, sqlQueryObjectDistinct);
  230.            
  231.         }finally{
  232.             org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.removeFields(sqlQueryObject,paginatedExpression,field);
  233.         }
  234.     }

  235.     @Override
  236.     public Object aggregate(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  237.                                                     JDBCExpression expression, FunctionField functionField) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  238.         Map<String,Object> map =
  239.             this.aggregate(jdbcProperties, log, connection, sqlQueryObject, expression, new FunctionField[]{functionField});
  240.         return org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.selectAggregateObject(map,functionField);
  241.     }
  242.    
  243.     @Override
  244.     public Map<String,Object> aggregate(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  245.                                                     JDBCExpression expression, FunctionField ... functionField) throws ServiceException,NotFoundException,NotImplementedException,Exception {                                                  
  246.        
  247.         org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.setFields(sqlQueryObject,expression,functionField);
  248.         try{
  249.             List<Map<String,Object>> list = selectEngine(jdbcProperties, log, connection, sqlQueryObject, expression);
  250.             return list.get(0);
  251.         }finally{
  252.             org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.removeFields(sqlQueryObject,expression,functionField);
  253.         }
  254.     }

  255.     @Override
  256.     public List<Map<String,Object>> groupBy(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  257.                                                     JDBCExpression expression, FunctionField ... functionField) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  258.        
  259.         if(expression.getGroupByFields().isEmpty()){
  260.             throw new ServiceException("GroupBy conditions not found in expression");
  261.         }
  262.        
  263.         org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.setFields(sqlQueryObject,expression,functionField);
  264.         try{
  265.             return selectEngine(jdbcProperties, log, connection, sqlQueryObject, expression);
  266.         }finally{
  267.             org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.removeFields(sqlQueryObject,expression,functionField);
  268.         }
  269.     }
  270.    

  271.     @Override
  272.     public List<Map<String,Object>> groupBy(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  273.                                                     JDBCPaginatedExpression paginatedExpression, FunctionField ... functionField) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  274.        
  275.         if(paginatedExpression.getGroupByFields().isEmpty()){
  276.             throw new ServiceException("GroupBy conditions not found in expression");
  277.         }
  278.        
  279.         org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.setFields(sqlQueryObject,paginatedExpression,functionField);
  280.         try{
  281.             return selectEngine(jdbcProperties, log, connection, sqlQueryObject, paginatedExpression);
  282.         }finally{
  283.             org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.removeFields(sqlQueryObject,paginatedExpression,functionField);
  284.         }
  285.     }
  286.    
  287.     protected List<Map<String,Object>> selectEngine(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  288.                                                 IExpression expression) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  289.         return selectEngine(jdbcProperties, log, connection, sqlQueryObject, expression, null);
  290.     }
  291.     protected List<Map<String,Object>> selectEngine(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  292.                                                 IExpression expression, ISQLQueryObject sqlQueryObjectDistinct) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  293.        
  294.         List<Object> listaQuery = new ArrayList<>();
  295.         List<JDBCObject> listaParams = new ArrayList<>();
  296.         List<Object> returnField = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareSelect(jdbcProperties, log, connection, sqlQueryObject,
  297.                                 expression, this.getAllarmeFieldConverter(), Allarme.model(),
  298.                                 listaQuery,listaParams);
  299.        
  300.         joinEngine(expression,sqlQueryObject);
  301.        
  302.         List<Map<String,Object>> list = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.select(jdbcProperties, log, connection,
  303.                                         org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareSqlQueryObjectForSelectDistinct(sqlQueryObject,sqlQueryObjectDistinct),
  304.                                         expression, this.getAllarmeFieldConverter(), Allarme.model(),
  305.                                         listaQuery,listaParams,returnField);
  306.         if(list!=null && !list.isEmpty()){
  307.             return list;
  308.         }
  309.         else{
  310.             throw org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.newNotFoundException();
  311.         }
  312.     }
  313.    
  314.     @Override
  315.     public List<Map<String,Object>> union(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  316.                                                 Union union, UnionExpression ... unionExpression) throws ServiceException,NotFoundException,NotImplementedException,Exception {    
  317.        
  318.         List<ISQLQueryObject> sqlQueryObjectInnerList = new ArrayList<>();
  319.         List<JDBCObject> jdbcObjects = new ArrayList<>();
  320.         List<Class<?>> returnClassTypes = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareUnion(jdbcProperties, log, connection, sqlQueryObject,
  321.                                 this.getAllarmeFieldConverter(), Allarme.model(),
  322.                                 sqlQueryObjectInnerList, jdbcObjects, union, unionExpression);
  323.        
  324.         if(unionExpression!=null){
  325.             for (int i = 0; i < unionExpression.length; i++) {
  326.                 UnionExpression ue = unionExpression[i];
  327.                 IExpression expression = ue.getExpression();
  328.                 joinEngine(expression,sqlQueryObjectInnerList.get(i));
  329.             }
  330.         }
  331.        
  332.         List<Map<String,Object>> list = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.union(jdbcProperties, log, connection, sqlQueryObject,
  333.                                         this.getAllarmeFieldConverter(), Allarme.model(),
  334.                                         sqlQueryObjectInnerList, jdbcObjects, returnClassTypes, union, unionExpression);
  335.         if(list!=null && !list.isEmpty()){
  336.             return list;
  337.         }
  338.         else{
  339.             throw org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.newNotFoundException();
  340.         }                              
  341.     }
  342.    
  343.     @Override
  344.     public NonNegativeNumber unionCount(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  345.                                                 Union union, UnionExpression ... unionExpression) throws ServiceException,NotFoundException,NotImplementedException,Exception {    
  346.        
  347.         List<ISQLQueryObject> sqlQueryObjectInnerList = new ArrayList<>();
  348.         List<JDBCObject> jdbcObjects = new ArrayList<>();
  349.         List<Class<?>> returnClassTypes = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareUnionCount(jdbcProperties, log, connection, sqlQueryObject,
  350.                                 this.getAllarmeFieldConverter(), Allarme.model(),
  351.                                 sqlQueryObjectInnerList, jdbcObjects, union, unionExpression);
  352.        
  353.         if(unionExpression!=null){
  354.             for (int i = 0; i < unionExpression.length; i++) {
  355.                 UnionExpression ue = unionExpression[i];
  356.                 IExpression expression = ue.getExpression();
  357.                 joinEngine(expression,sqlQueryObjectInnerList.get(i));
  358.             }
  359.         }
  360.        
  361.         NonNegativeNumber number = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.unionCount(jdbcProperties, log, connection, sqlQueryObject,
  362.                                         this.getAllarmeFieldConverter(), Allarme.model(),
  363.                                         sqlQueryObjectInnerList, jdbcObjects, returnClassTypes, union, unionExpression);
  364.         if(number!=null && number.longValue()>=0){
  365.             return number;
  366.         }
  367.         else{
  368.             throw org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.newNotFoundException();
  369.         }
  370.     }



  371.     // -- ConstructorExpression

  372.     @Override
  373.     public JDBCExpression newExpression(Logger log) throws NotImplementedException, ServiceException {
  374.         try{
  375.             return new JDBCExpression(this.getAllarmeFieldConverter());
  376.         }catch(Exception e){
  377.             throw new ServiceException(e);
  378.         }
  379.     }


  380.     @Override
  381.     public JDBCPaginatedExpression newPaginatedExpression(Logger log) throws NotImplementedException, ServiceException {
  382.         try{
  383.             return new JDBCPaginatedExpression(this.getAllarmeFieldConverter());
  384.         }catch(Exception e){
  385.             throw new ServiceException(e);
  386.         }
  387.     }
  388.    
  389.     @Override
  390.     public JDBCExpression toExpression(JDBCPaginatedExpression paginatedExpression, Logger log) throws NotImplementedException, ServiceException {
  391.         try{
  392.             return new JDBCExpression(paginatedExpression);
  393.         }catch(Exception e){
  394.             throw new ServiceException(e);
  395.         }
  396.     }

  397.     @Override
  398.     public JDBCPaginatedExpression toPaginatedExpression(JDBCExpression expression, Logger log) throws NotImplementedException, ServiceException {
  399.         try{
  400.             return new JDBCPaginatedExpression(expression);
  401.         }catch(Exception e){
  402.             throw new ServiceException(e);
  403.         }
  404.     }
  405.    
  406.    
  407.    
  408.     // -- DB

  409.     @Override
  410.     public void mappingTableIds(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdAllarme id, Allarme obj) throws NotFoundException,NotImplementedException,ServiceException,Exception{
  411.         _mappingTableIds(jdbcProperties,log,connection,sqlQueryObject,obj,
  412.                 this.get(jdbcProperties,log,connection,sqlQueryObject,id,null));
  413.     }
  414.    
  415.     @Override
  416.     public void mappingTableIds(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId, Allarme obj) throws NotFoundException,NotImplementedException,ServiceException,Exception{
  417.         _mappingTableIds(jdbcProperties,log,connection,sqlQueryObject,obj,
  418.                 this.get(jdbcProperties,log,connection,sqlQueryObject,tableId,null));
  419.     }
  420.     private void _mappingTableIds(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, Allarme obj, Allarme imgSaved) throws NotFoundException,NotImplementedException,ServiceException,Exception{
  421.         if(imgSaved==null){
  422.             return;
  423.         }
  424.         obj.setId(imgSaved.getId());
  425.         if(obj.getMail()!=null &&
  426.                 imgSaved.getMail()!=null){
  427.             obj.getMail().setId(imgSaved.getMail().getId());
  428.         }
  429.         if(obj.getScript()!=null &&
  430.                 imgSaved.getScript()!=null){
  431.             obj.getScript().setId(imgSaved.getScript().getId());
  432.         }
  433.         if(obj.getFiltro()!=null &&
  434.                 imgSaved.getFiltro()!=null){
  435.             obj.getFiltro().setId(imgSaved.getFiltro().getId());
  436.         }
  437.         if(obj.getGroupBy()!=null &&
  438.                 imgSaved.getGroupBy()!=null){
  439.             obj.getGroupBy().setId(imgSaved.getGroupBy().getId());
  440.         }
  441.         if(obj.getAllarmeParametroList()!=null){
  442.             List<org.openspcoop2.core.allarmi.AllarmeParametro> listObj_ = obj.getAllarmeParametroList();
  443.             for(org.openspcoop2.core.allarmi.AllarmeParametro itemObj_ : listObj_){
  444.                 org.openspcoop2.core.allarmi.AllarmeParametro itemAlreadySaved_ = null;
  445.                 if(imgSaved.getAllarmeParametroList()!=null){
  446.                     List<org.openspcoop2.core.allarmi.AllarmeParametro> listImgSaved_ = imgSaved.getAllarmeParametroList();
  447.                     for(org.openspcoop2.core.allarmi.AllarmeParametro itemImgSaved_ : listImgSaved_){
  448.                         boolean objEqualsToImgSaved_ = false;
  449.                         objEqualsToImgSaved_ = org.openspcoop2.generic_project.utils.Utilities.equals(itemObj_.getIdParametro(),itemImgSaved_.getIdParametro());
  450.                         if(objEqualsToImgSaved_){
  451.                             itemAlreadySaved_=itemImgSaved_;
  452.                             break;
  453.                         }
  454.                     }
  455.                 }
  456.                 if(itemAlreadySaved_!=null){
  457.                     itemObj_.setId(itemAlreadySaved_.getId());
  458.                 }
  459.             }
  460.         }
  461.              
  462.     }
  463.    
  464.     @Override
  465.     public Allarme get(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotFoundException, MultipleResultException, NotImplementedException, ServiceException, Exception {
  466.         return this.getEngine(jdbcProperties, log, connection, sqlQueryObject, Long.valueOf(tableId), idMappingResolutionBehaviour);
  467.     }
  468.    
  469.     private Allarme getEngine(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, Long tableId, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotFoundException, MultipleResultException, NotImplementedException, ServiceException, Exception {
  470.    
  471.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  472.                     new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);
  473.        
  474.         ISQLQueryObject sqlQueryObjectGet = sqlQueryObject.newSQLQueryObject();
  475.                
  476.         Allarme allarme = new Allarme();
  477.        

  478.         // Object allarme
  479.         sqlQueryObjectGet.setANDLogicOperator(true);
  480.         sqlQueryObjectGet.addFromTable(this.getAllarmeFieldConverter().toTable(Allarme.model()));
  481.         sqlQueryObjectGet.addSelectField("id");
  482.         sqlQueryObjectGet.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().NOME,true));
  483.         sqlQueryObjectGet.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().ALIAS,true));
  484.         sqlQueryObjectGet.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().DESCRIZIONE,true));
  485.         sqlQueryObjectGet.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().TIPO,true));
  486.         sqlQueryObjectGet.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().TIPO_ALLARME,true));
  487.         sqlQueryObjectGet.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().MAIL.INVIA,true));
  488.         sqlQueryObjectGet.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().MAIL.INVIA_WARNING,true));
  489.         sqlQueryObjectGet.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().MAIL.DESTINATARI,true));
  490.         sqlQueryObjectGet.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().MAIL.SUBJECT,true));
  491.         sqlQueryObjectGet.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().MAIL.BODY,true));
  492.         sqlQueryObjectGet.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().SCRIPT.INVOCA,true));
  493.         sqlQueryObjectGet.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().SCRIPT.INVOCA_WARNING,true));
  494.         sqlQueryObjectGet.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().SCRIPT.COMMAND,true));
  495.         sqlQueryObjectGet.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().SCRIPT.ARGS,true));
  496.         sqlQueryObjectGet.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().STATO_PRECEDENTE,true));
  497.         sqlQueryObjectGet.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().STATO,true));
  498.         sqlQueryObjectGet.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().DETTAGLIO_STATO,true));
  499.         sqlQueryObjectGet.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().LASTTIMESTAMP_CREATE,true));
  500.         sqlQueryObjectGet.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().LASTTIMESTAMP_UPDATE,true));
  501.         sqlQueryObjectGet.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().ENABLED,true));
  502.         sqlQueryObjectGet.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().ACKNOWLEDGED,true));
  503.         sqlQueryObjectGet.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().DETTAGLIO_ACKNOWLEDGED,true));
  504.         sqlQueryObjectGet.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().TIPO_PERIODO,true));
  505.         sqlQueryObjectGet.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().PERIODO,true));
  506.         sqlQueryObjectGet.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().FILTRO.ENABLED,true));
  507.         sqlQueryObjectGet.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().FILTRO.PROTOCOLLO,true));
  508.         sqlQueryObjectGet.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().FILTRO.RUOLO_PORTA,true));
  509.         sqlQueryObjectGet.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().FILTRO.NOME_PORTA,true));
  510.         sqlQueryObjectGet.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().FILTRO.TIPO_FRUITORE,true));
  511.         sqlQueryObjectGet.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().FILTRO.NOME_FRUITORE,true));
  512.         sqlQueryObjectGet.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().FILTRO.RUOLO_FRUITORE,true));
  513.         sqlQueryObjectGet.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().FILTRO.SERVIZIO_APPLICATIVO_FRUITORE,true));
  514.         sqlQueryObjectGet.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().FILTRO.TIPO_EROGATORE,true));
  515.         sqlQueryObjectGet.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().FILTRO.NOME_EROGATORE,true));
  516.         sqlQueryObjectGet.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().FILTRO.RUOLO_EROGATORE,true));
  517.         sqlQueryObjectGet.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().FILTRO.TAG,true));
  518.         sqlQueryObjectGet.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().FILTRO.TIPO_SERVIZIO,true));
  519.         sqlQueryObjectGet.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().FILTRO.NOME_SERVIZIO,true));
  520.         sqlQueryObjectGet.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().FILTRO.VERSIONE_SERVIZIO,true));
  521.         sqlQueryObjectGet.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().FILTRO.AZIONE,true));
  522.         sqlQueryObjectGet.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().GROUP_BY.ENABLED,true));
  523.         sqlQueryObjectGet.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().GROUP_BY.RUOLO_PORTA,true));
  524.         sqlQueryObjectGet.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().GROUP_BY.PROTOCOLLO,true));
  525.         sqlQueryObjectGet.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().GROUP_BY.FRUITORE,true));
  526.         sqlQueryObjectGet.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().GROUP_BY.SERVIZIO_APPLICATIVO_FRUITORE,true));
  527.         sqlQueryObjectGet.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().GROUP_BY.IDENTIFICATIVO_AUTENTICATO,true));
  528.         sqlQueryObjectGet.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().GROUP_BY.TOKEN,true));
  529.         sqlQueryObjectGet.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().GROUP_BY.EROGATORE,true));
  530.         sqlQueryObjectGet.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().GROUP_BY.SERVIZIO,true));
  531.         sqlQueryObjectGet.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().GROUP_BY.AZIONE,true));
  532.         sqlQueryObjectGet.addWhereCondition("id=?");

  533.         // Get allarme
  534.         allarme = (Allarme) jdbcUtilities.executeQuerySingleResult(sqlQueryObjectGet.createSQLQuery(), jdbcProperties.isShowSql(), Allarme.model(), this.getAllarmeFetch(),
  535.             new JDBCObject(tableId,Long.class));



  536.         // Object allarme_allarmeParametro
  537.         ISQLQueryObject sqlQueryObjectGetAllarmeParametro = sqlQueryObjectGet.newSQLQueryObject();
  538.         sqlQueryObjectGetAllarmeParametro.setANDLogicOperator(true);
  539.         sqlQueryObjectGetAllarmeParametro.addFromTable(this.getAllarmeFieldConverter().toTable(Allarme.model().ALLARME_PARAMETRO));
  540.         sqlQueryObjectGetAllarmeParametro.addSelectField("chk_param_id");
  541.         sqlQueryObjectGetAllarmeParametro.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().ALLARME_PARAMETRO.ID_PARAMETRO,true));
  542.         sqlQueryObjectGetAllarmeParametro.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().ALLARME_PARAMETRO.VALORE,true));
  543.         sqlQueryObjectGetAllarmeParametro.addWhereCondition("id_allarme=?");

  544.         // Get allarme_allarmeParametro
  545.         java.util.List<Object> allarme_allarmeParametro_list = (java.util.List<Object>) jdbcUtilities.executeQuery(sqlQueryObjectGetAllarmeParametro.createSQLQuery(), jdbcProperties.isShowSql(), Allarme.model().ALLARME_PARAMETRO, this.getAllarmeFetch(),
  546.             new JDBCObject(allarme.getId(),Long.class));

  547.         if(allarme_allarmeParametro_list != null) {
  548.             for (Object allarme_allarmeParametro_object: allarme_allarmeParametro_list) {
  549.                 AllarmeParametro allarme_allarmeParametro = (AllarmeParametro) allarme_allarmeParametro_object;


  550.                 allarme.addAllarmeParametro(allarme_allarmeParametro);
  551.             }
  552.         }

  553.        
  554.         return allarme;  
  555.    
  556.     }
  557.    
  558.     @Override
  559.     public boolean exists(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId) throws MultipleResultException, NotImplementedException, ServiceException, Exception {
  560.         return this._exists(jdbcProperties, log, connection, sqlQueryObject, Long.valueOf(tableId));
  561.     }
  562.    
  563.     private boolean _exists(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, Long tableId) throws MultipleResultException, NotImplementedException, ServiceException, Exception {
  564.    
  565.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  566.                     new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);
  567.                
  568.         boolean existsAllarme = false;

  569.         sqlQueryObject = sqlQueryObject.newSQLQueryObject();
  570.         sqlQueryObject.setANDLogicOperator(true);

  571.         sqlQueryObject.addFromTable(this.getAllarmeFieldConverter().toTable(Allarme.model()));
  572.         sqlQueryObject.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().NOME,true));
  573.         sqlQueryObject.addWhereCondition("id=?");


  574.         // Exists allarme
  575.         existsAllarme = jdbcUtilities.exists(sqlQueryObject.createSQLQuery(), jdbcProperties.isShowSql(),
  576.             new JDBCObject(tableId,Long.class));

  577.        
  578.         return existsAllarme;
  579.    
  580.     }
  581.    
  582.     private void joinEngine(IExpression expression, ISQLQueryObject sqlQueryObject) throws NotImplementedException, ServiceException, Exception{
  583.    
  584.         if(expression.inUseModel(Allarme.model().ALLARME_PARAMETRO,false)){
  585.             String tableName1 = this.getAllarmeFieldConverter().toTable(Allarme.model().ALLARME_PARAMETRO);
  586.             String tableName2 = this.getAllarmeFieldConverter().toTable(Allarme.model());
  587.             sqlQueryObject.addWhereCondition(tableName1+".id_allarme="+tableName2+".id");
  588.         }
  589.        
  590.     }
  591.    
  592.     protected java.util.List<Object> getRootTablePrimaryKeyValuesEngine(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdAllarme id) throws NotFoundException, ServiceException, NotImplementedException, Exception{
  593.         // Identificativi
  594.         java.util.List<Object> rootTableIdValues = new java.util.ArrayList<>();
  595.         Long longId = this.findIdAllarme(jdbcProperties, log, connection, sqlQueryObject.newSQLQueryObject(), id, true);
  596.         rootTableIdValues.add(longId);
  597.        
  598.         return rootTableIdValues;
  599.     }
  600.    
  601.     protected Map<String, List<IField>> getMapTableToPKColumnEngine() throws NotImplementedException, Exception{
  602.    
  603.         AllarmeFieldConverter converter = this.getAllarmeFieldConverter();
  604.         Map<String, List<IField>> mapTableToPKColumn = new java.util.HashMap<>();
  605.         UtilsTemplate<IField> utilities = new UtilsTemplate<>();

  606.         // Allarme.model()
  607.         mapTableToPKColumn.put(converter.toTable(Allarme.model()),
  608.             utilities.newList(
  609.                 new CustomField("id", Long.class, "id", converter.toTable(Allarme.model()))
  610.             ));

  611.         // Allarme.model().MAIL
  612.         mapTableToPKColumn.put(converter.toTable(Allarme.model().MAIL),
  613.             utilities.newList(
  614.                 new CustomField("id", Long.class, "id", converter.toTable(Allarme.model().MAIL))
  615.             ));

  616.         // Allarme.model().SCRIPT
  617.         mapTableToPKColumn.put(converter.toTable(Allarme.model().SCRIPT),
  618.             utilities.newList(
  619.                 new CustomField("id", Long.class, "id", converter.toTable(Allarme.model().SCRIPT))
  620.             ));

  621.         // Allarme.model().FILTRO
  622.         mapTableToPKColumn.put(converter.toTable(Allarme.model().FILTRO),
  623.             utilities.newList(
  624.                 new CustomField("id", Long.class, "id", converter.toTable(Allarme.model().FILTRO))
  625.             ));

  626.         // Allarme.model().GROUP_BY
  627.         mapTableToPKColumn.put(converter.toTable(Allarme.model().GROUP_BY),
  628.             utilities.newList(
  629.                 new CustomField("id", Long.class, "id", converter.toTable(Allarme.model().GROUP_BY))
  630.             ));

  631.         // Allarme.model().ALLARME_PARAMETRO
  632.         mapTableToPKColumn.put(converter.toTable(Allarme.model().ALLARME_PARAMETRO),
  633.             utilities.newList(
  634.                 new CustomField("id", Long.class, "id", converter.toTable(Allarme.model().ALLARME_PARAMETRO))
  635.             ));
  636.        
  637.         return mapTableToPKColumn;      
  638.     }
  639.    
  640.     @Override
  641.     public List<Long> findAllTableIds(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCPaginatedExpression paginatedExpression) throws ServiceException, NotImplementedException, Exception {
  642.        
  643.         List<Long> list = new ArrayList<Long>();

  644.         sqlQueryObject.setSelectDistinct(true);
  645.         sqlQueryObject.setANDLogicOperator(true);
  646.         sqlQueryObject.addSelectField(this.getAllarmeFieldConverter().toTable(Allarme.model())+".id");
  647.         Class<?> objectIdClass = Long.class;
  648.        
  649.         List<Object> listaQuery = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareFindAll(jdbcProperties, log, connection, sqlQueryObject, paginatedExpression,
  650.                                                 this.getAllarmeFieldConverter(), Allarme.model());
  651.        
  652.         joinEngine(paginatedExpression,sqlQueryObject);
  653.        
  654.         List<Object> listObjects = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.findAll(jdbcProperties, log, connection, sqlQueryObject, paginatedExpression,
  655.                                                                             this.getAllarmeFieldConverter(), Allarme.model(), objectIdClass, listaQuery);
  656.         for(Object object: listObjects) {
  657.             list.add((Long)object);
  658.         }

  659.         return list;
  660.        
  661.     }
  662.    
  663.     @Override
  664.     public long findTableId(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCExpression expression) throws ServiceException, NotFoundException, MultipleResultException, NotImplementedException, Exception {
  665.    
  666.         sqlQueryObject.setSelectDistinct(true);
  667.         sqlQueryObject.setANDLogicOperator(true);
  668.         sqlQueryObject.addSelectField(this.getAllarmeFieldConverter().toTable(Allarme.model())+".id");
  669.         Class<?> objectIdClass = Long.class;
  670.        
  671.         List<Object> listaQuery = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareFind(jdbcProperties, log, connection, sqlQueryObject, expression,
  672.                                                 this.getAllarmeFieldConverter(), Allarme.model());
  673.        
  674.         joinEngine(expression,sqlQueryObject);

  675.         Object res = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.find(jdbcProperties, log, connection, sqlQueryObject, expression,
  676.                                                         this.getAllarmeFieldConverter(), Allarme.model(), objectIdClass, listaQuery);
  677.         if(res!=null && (((Long) res).longValue()>0) ){
  678.             return ((Long) res).longValue();
  679.         }
  680.         else{
  681.             throw org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.newNotFoundException();
  682.         }
  683.        
  684.     }

  685.     @Override
  686.     public InUse inUse(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId) throws ServiceException, NotFoundException, NotImplementedException, Exception {
  687.         return this.inUseEngine(jdbcProperties, log, connection, sqlQueryObject, Long.valueOf(tableId));
  688.     }

  689.     private InUse inUseEngine(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, Long tableId) throws ServiceException, NotFoundException, NotImplementedException, Exception {

  690.         InUse inUse = new InUse();
  691.         inUse.setInUse(false);
  692.        
  693.         /*
  694.          * TODO: implement code that checks whether the object identified by the id parameter is used by other objects
  695.         */
  696.        
  697.         // Delete this line when you have implemented the method
  698.         int throwNotImplemented = 1;
  699.         if(throwNotImplemented==1){
  700.                 throw new NotImplementedException("NotImplemented");
  701.         }
  702.         // Delete this line when you have implemented the method

  703.         return inUse;

  704.     }
  705.    
  706.     @Override
  707.     public IdAllarme findId(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId, boolean throwNotFound)
  708.             throws NotFoundException, ServiceException, NotImplementedException, Exception {
  709.        
  710.         if(tableId<=0) {
  711.             throw new ServiceException("Id undefined");
  712.         }
  713.        
  714.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  715.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);

  716.         ISQLQueryObject sqlQueryObjectGet = sqlQueryObject.newSQLQueryObject();              

  717.         // Object _allarme
  718.         sqlQueryObjectGet.addFromTable(this.getAllarmeFieldConverter().toTable(Allarme.model()));
  719.         sqlQueryObjectGet.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().NOME,true));
  720.         sqlQueryObjectGet.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().TIPO,true));
  721.         sqlQueryObjectGet.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().ENABLED,true));
  722.         sqlQueryObjectGet.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().ALIAS,true));
  723.         sqlQueryObjectGet.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().FILTRO.RUOLO_PORTA,true));
  724.         sqlQueryObjectGet.addSelectField(this.getAllarmeFieldConverter().toColumn(Allarme.model().FILTRO.NOME_PORTA,true));
  725.         sqlQueryObjectGet.setANDLogicOperator(true);
  726.         sqlQueryObjectGet.addWhereCondition("id=?");

  727.         // Recupero _allarme
  728.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject [] searchParams_allarme = new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject [] {
  729.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(tableId,Long.class)
  730.         };
  731.         List<Class<?>> listaFieldIdReturnType_allarme = new ArrayList<Class<?>>();
  732.         listaFieldIdReturnType_allarme.add(Allarme.model().NOME.getFieldType());
  733.         listaFieldIdReturnType_allarme.add(Allarme.model().TIPO.getFieldType());
  734.         listaFieldIdReturnType_allarme.add(Allarme.model().ENABLED.getFieldType());
  735.         listaFieldIdReturnType_allarme.add(Allarme.model().ALIAS.getFieldType());
  736.         listaFieldIdReturnType_allarme.add(Allarme.model().FILTRO.RUOLO_PORTA.getFieldType());
  737.         listaFieldIdReturnType_allarme.add(Allarme.model().FILTRO.NOME_PORTA.getFieldType());
  738.         org.openspcoop2.core.allarmi.IdAllarme idAllarme = null;
  739.         List<Object> listaFieldId_allarme = jdbcUtilities.executeQuerySingleResult(sqlQueryObjectGet.createSQLQuery(), jdbcProperties.isShowSql(),
  740.                 listaFieldIdReturnType_allarme, searchParams_allarme);
  741.         if(listaFieldId_allarme==null || listaFieldId_allarme.size()<=0){
  742.             if(throwNotFound){
  743.                 throw org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.newNotFoundException();
  744.             }
  745.         }
  746.         else{
  747.             // set _allarme
  748.             idAllarme = new org.openspcoop2.core.allarmi.IdAllarme();
  749.             idAllarme.setNome((String)listaFieldId_allarme.get(0));
  750.             idAllarme.setTipo((String)listaFieldId_allarme.get(1));
  751.             idAllarme.setEnabled((Integer)listaFieldId_allarme.get(2));
  752.             idAllarme.setAlias((String)listaFieldId_allarme.get(3));
  753.             Object ruoloPorta = listaFieldId_allarme.get(4);
  754.             if(ruoloPorta!=null) {
  755.                 if(ruoloPorta instanceof RuoloPorta) {
  756.                     idAllarme.setFiltroRuoloPorta((RuoloPorta)ruoloPorta);
  757.                 }
  758.                 else if(ruoloPorta instanceof String) {
  759.                     idAllarme.setFiltroRuoloPorta(RuoloPorta.toEnumConstant((String)ruoloPorta));
  760.                 }
  761.             }
  762.             Object nomePorta = listaFieldId_allarme.get(5);
  763.             if(nomePorta!=null) {
  764.                 if(nomePorta instanceof String) {
  765.                     idAllarme.setFiltroNomePorta((String)nomePorta);
  766.                 }
  767.             }
  768.         }
  769.        
  770.         return idAllarme;
  771.        
  772.     }

  773.     @Override
  774.     public Long findTableId(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdAllarme id, boolean throwNotFound)
  775.             throws NotFoundException, ServiceException, NotImplementedException, Exception {
  776.    
  777.         return this.findIdAllarme(jdbcProperties,log,connection,sqlQueryObject,id,throwNotFound);
  778.            
  779.     }
  780.    
  781.     @Override
  782.     public List<List<Object>> nativeQuery(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  783.                                             String sql,List<Class<?>> returnClassTypes,Object ... param) throws ServiceException,NotFoundException,NotImplementedException,Exception{
  784.        
  785.         return org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.nativeQuery(jdbcProperties, log, connection, sqlQueryObject,
  786.                                                                                             sql,returnClassTypes,param);
  787.                                                        
  788.     }
  789.    
  790.     protected Long findIdAllarme(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdAllarme id, boolean throwNotFound) throws NotFoundException, ServiceException, NotImplementedException, Exception {

  791.         if(id==null || id.getNome()==null) {
  792.             throw new ServiceException("Id undefined");
  793.         }
  794.        
  795.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  796.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);

  797.         ISQLQueryObject sqlQueryObjectGet = sqlQueryObject.newSQLQueryObject();              

  798.         // Object _allarme
  799.         sqlQueryObjectGet.addFromTable(this.getAllarmeFieldConverter().toTable(Allarme.model()));
  800.         sqlQueryObjectGet.addSelectField("id");
  801.         // Devono essere mappati nella where condition i metodi dell'oggetto id.getXXX
  802.         sqlQueryObjectGet.setANDLogicOperator(true);
  803.         sqlQueryObjectGet.setSelectDistinct(true);
  804.         sqlQueryObjectGet.addWhereCondition(this.getAllarmeFieldConverter().toColumn(Allarme.model().NOME,true)+"=?");
  805.        
  806.         // Recupero _allarme
  807.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject [] searchParams_allarme = new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject [] {
  808.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(id.getNome(),String.class)
  809.         };
  810.         Long idAllarme = null;
  811.         try{
  812.             idAllarme = (Long) jdbcUtilities.executeQuerySingleResult(sqlQueryObjectGet.createSQLQuery(), jdbcProperties.isShowSql(),
  813.                         Long.class, searchParams_allarme);
  814.         }catch(NotFoundException notFound){
  815.             if(throwNotFound){
  816.                 throw new NotFoundException(notFound);
  817.             }
  818.         }
  819.         if(idAllarme==null || idAllarme<=0){
  820.             if(throwNotFound){
  821.                 throw org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.newNotFoundException();
  822.             }
  823.         }
  824.        
  825.         return idAllarme;
  826.     }
  827. }