JDBCPortaDelegataServiceSearchImpl.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.commons.search.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.commons.search.IdPortaDelegata;
  26. import org.openspcoop2.core.commons.search.IdServizioApplicativo;
  27. import org.openspcoop2.core.commons.search.IdSoggetto;
  28. import org.openspcoop2.core.commons.search.PortaDelegata;
  29. import org.openspcoop2.core.commons.search.PortaDelegataAzione;
  30. import org.openspcoop2.core.commons.search.PortaDelegataServizioApplicativo;
  31. import org.openspcoop2.core.commons.search.dao.IDBSoggettoServiceSearch;
  32. import org.openspcoop2.core.commons.search.dao.jdbc.converter.PortaDelegataFieldConverter;
  33. import org.openspcoop2.core.commons.search.dao.jdbc.fetch.PortaDelegataFetch;
  34. import org.openspcoop2.core.commons.search.utils.ExpressionProperties;
  35. import org.openspcoop2.generic_project.beans.AliasField;
  36. import org.openspcoop2.generic_project.beans.CustomField;
  37. import org.openspcoop2.generic_project.beans.FunctionField;
  38. import org.openspcoop2.generic_project.beans.IField;
  39. import org.openspcoop2.generic_project.beans.InUse;
  40. import org.openspcoop2.generic_project.beans.NonNegativeNumber;
  41. import org.openspcoop2.generic_project.beans.Union;
  42. import org.openspcoop2.generic_project.beans.UnionExpression;
  43. import org.openspcoop2.generic_project.dao.jdbc.IJDBCServiceSearchWithId;
  44. import org.openspcoop2.generic_project.dao.jdbc.JDBCExpression;
  45. import org.openspcoop2.generic_project.dao.jdbc.JDBCPaginatedExpression;
  46. import org.openspcoop2.generic_project.dao.jdbc.JDBCServiceManagerProperties;
  47. import org.openspcoop2.generic_project.dao.jdbc.utils.IJDBCFetch;
  48. import org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject;
  49. import org.openspcoop2.generic_project.exception.MultipleResultException;
  50. import org.openspcoop2.generic_project.exception.NotFoundException;
  51. import org.openspcoop2.generic_project.exception.NotImplementedException;
  52. import org.openspcoop2.generic_project.exception.ServiceException;
  53. import org.openspcoop2.generic_project.expression.IExpression;
  54. import org.openspcoop2.generic_project.expression.impl.sql.ISQLFieldConverter;
  55. import org.openspcoop2.generic_project.utils.UtilsTemplate;
  56. import org.openspcoop2.utils.sql.ISQLQueryObject;
  57. import org.slf4j.Logger;

  58. /**    
  59.  * JDBCPortaDelegataServiceSearchImpl
  60.  *
  61.  * @author Poli Andrea (poli@link.it)
  62.  * @author $Author$
  63.  * @version $Rev$, $Date$
  64.  */
  65. public class JDBCPortaDelegataServiceSearchImpl implements IJDBCServiceSearchWithId<PortaDelegata, IdPortaDelegata, JDBCServiceManager> {

  66.     private PortaDelegataFieldConverter _portaDelegataFieldConverter = null;
  67.     public PortaDelegataFieldConverter getPortaDelegataFieldConverter() {
  68.         if(this._portaDelegataFieldConverter==null){
  69.             this._portaDelegataFieldConverter = new PortaDelegataFieldConverter(this.jdbcServiceManager.getJdbcProperties().getDatabaseType());
  70.         }      
  71.         return this._portaDelegataFieldConverter;
  72.     }
  73.     @Override
  74.     public ISQLFieldConverter getFieldConverter() {
  75.         return this.getPortaDelegataFieldConverter();
  76.     }
  77.    
  78.     private PortaDelegataFetch portaDelegataFetch = new PortaDelegataFetch();
  79.     public PortaDelegataFetch getPortaDelegataFetch() {
  80.         return this.portaDelegataFetch;
  81.     }
  82.     @Override
  83.     public IJDBCFetch getFetch() {
  84.         return getPortaDelegataFetch();
  85.     }
  86.    
  87.    
  88.     private JDBCServiceManager jdbcServiceManager = null;

  89.     @Override
  90.     public void setServiceManager(JDBCServiceManager serviceManager) throws ServiceException{
  91.         this.jdbcServiceManager = serviceManager;
  92.     }
  93.    
  94.     @Override
  95.     public JDBCServiceManager getServiceManager() throws ServiceException{
  96.         return this.jdbcServiceManager;
  97.     }
  98.     public JDBCServiceManager getServiceManager(Connection connection, JDBCServiceManagerProperties jdbcProperties, Logger log) throws ServiceException{
  99.         return new JDBCServiceManager(connection, jdbcProperties, log);
  100.     }
  101.    

  102.     @Override
  103.     public IdPortaDelegata convertToId(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, PortaDelegata portaDelegata) throws NotImplementedException, ServiceException, Exception{
  104.    
  105.         IdPortaDelegata idPortaDelegata = new IdPortaDelegata();
  106.         idPortaDelegata.setNome(portaDelegata.getNome());
  107.         return idPortaDelegata;
  108.     }
  109.    
  110.     @Override
  111.     public PortaDelegata get(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdPortaDelegata id, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotFoundException, MultipleResultException, NotImplementedException, ServiceException,Exception {
  112.         Long id_portaDelegata = ( (id!=null && id.getId()!=null && id.getId()>0) ? id.getId() : this.findIdPortaDelegata(jdbcProperties, log, connection, sqlQueryObject, id, true));
  113.         return this.getEngine(jdbcProperties, log, connection, sqlQueryObject, id_portaDelegata,idMappingResolutionBehaviour);
  114.        
  115.        
  116.     }
  117.    
  118.     @Override
  119.     public boolean exists(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdPortaDelegata id) throws MultipleResultException, NotImplementedException, ServiceException,Exception {

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

  127.         List<IdPortaDelegata> list = new ArrayList<IdPortaDelegata>();

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

  134.         List<Long> ids = this.findAllTableIds(jdbcProperties, log, connection, sqlQueryObject, expression);
  135.        
  136.         for(Long id: ids) {
  137.             PortaDelegata portaDelegata = this.get(jdbcProperties, log, connection, sqlQueryObject, id, idMappingResolutionBehaviour);
  138.             IdPortaDelegata idPortaDelegata = this.convertToId(jdbcProperties,log,connection,sqlQueryObject,portaDelegata);
  139.             list.add(idPortaDelegata);
  140.         }

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

  148.         List<PortaDelegata> list = new ArrayList<PortaDelegata>();
  149.        
  150.         boolean soloDatiIdentificativiServizio = ExpressionProperties.isEnabledSoloDatiIdentificativiServizio(expression);
  151.        
  152.         if(soloDatiIdentificativiServizio){
  153.            
  154.             List<IField> fields = new ArrayList<IField>();
  155.             fields.add(PortaDelegata.model().NOME);
  156.             fields.add(PortaDelegata.model().STATO);
  157.             fields.add(PortaDelegata.model().TIPO_SOGGETTO_EROGATORE);
  158.             fields.add(PortaDelegata.model().NOME_SOGGETTO_EROGATORE);
  159.             fields.add(PortaDelegata.model().TIPO_SERVIZIO);
  160.             fields.add(PortaDelegata.model().NOME_SERVIZIO);
  161.             fields.add(PortaDelegata.model().VERSIONE_SERVIZIO);
  162.             fields.add(PortaDelegata.model().MODE_AZIONE);
  163.             fields.add(PortaDelegata.model().NOME_AZIONE);
  164.             fields.add(PortaDelegata.model().NOME_PORTA_DELEGANTE_AZIONE);
  165.            
  166.             String aliasSoggettoTipo = "proprietarioSoggettoTipo";
  167.             fields.add(new AliasField(PortaDelegata.model().ID_SOGGETTO.TIPO, aliasSoggettoTipo));
  168.             String aliasSoggettoNome = "proprietarioSoggettoNome";
  169.             fields.add(new AliasField(PortaDelegata.model().ID_SOGGETTO.NOME, aliasSoggettoNome));
  170.            
  171.             List<Map<String, Object>> returnMap = null;
  172.             try{
  173.                 // non usare true altrimenti non funzionano alcuni meccanismi di ricerca, ad es. la valorizzazione dei select field nel servizio della govwayMonitor.
  174.                 // Tanto le join non comportano righe multiple uguali
  175.                 boolean distinct = false;
  176.                 returnMap = this.select(jdbcProperties, log, connection, sqlQueryObject, expression, distinct, fields.toArray(new IField[1]));
  177.                
  178.                 for(Map<String, Object> map: returnMap) {
  179.                    
  180.                     PortaDelegata pd = (PortaDelegata) this.getPortaDelegataFetch().fetch(jdbcProperties.getDatabase(), PortaDelegata.model(), map);
  181.                    
  182.                     Object proprietarioSoggettoTipo = this.getObjectFromMap(map, aliasSoggettoTipo);
  183.                     Object proprietarioSoggettoNome = this.getObjectFromMap(map, aliasSoggettoNome);
  184.                     if(proprietarioSoggettoTipo!=null && proprietarioSoggettoNome!=null) {
  185.                         IdSoggetto idSoggetto = new IdSoggetto();
  186.                         if(proprietarioSoggettoTipo!=null && proprietarioSoggettoTipo instanceof String) {
  187.                             idSoggetto.setTipo((String) proprietarioSoggettoTipo);
  188.                         }
  189.                         if(proprietarioSoggettoNome!=null && proprietarioSoggettoNome instanceof String) {
  190.                             idSoggetto.setNome((String) proprietarioSoggettoNome);
  191.                         }
  192.                         pd.setIdSoggetto(idSoggetto);
  193.                     }          
  194.                    
  195.                     list.add(pd);
  196.                 }
  197.             }catch(NotFoundException notFound){}
  198.         }
  199.         else {
  200.             // TODO: implementazione non efficiente.
  201.             // Per ottenere una implementazione efficiente:
  202.             // 1. Usare metodo select di questa classe indirizzando esattamente i field necessari
  203.             // 2. Usare metodo getPortaDelegataFetch() sul risultato della select per ottenere un oggetto PortaDelegata
  204.             //    La fetch con la map inserirĂ  nell'oggetto solo i valori estratti
  205.    
  206.             List<Long> ids = this.findAllTableIds(jdbcProperties, log, connection, sqlQueryObject, expression);
  207.            
  208.             for(Long id: ids) {
  209.                 list.add(this.get(jdbcProperties, log, connection, sqlQueryObject, id, idMappingResolutionBehaviour));
  210.             }
  211.         }

  212.         return list;      
  213.        
  214.     }
  215.    
  216.     private Object getObjectFromMap(Map<String,Object> map,String name){
  217.         if(map==null){
  218.             return null;
  219.         }
  220.         else if(map.containsKey(name)){
  221.             Object o = map.get(name);
  222.             if(o instanceof org.apache.commons.lang.ObjectUtils.Null){
  223.                 return null;
  224.             }
  225.             else{
  226.                 return o;
  227.             }
  228.         }
  229.         else{
  230.             return null;
  231.         }
  232.     }
  233.    
  234.     @Override
  235.     public PortaDelegata find(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCExpression expression, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour)
  236.         throws NotFoundException, MultipleResultException, NotImplementedException, ServiceException,Exception {

  237.         long id = this.findTableId(jdbcProperties, log, connection, sqlQueryObject, expression);
  238.         if(id>0){
  239.             return this.get(jdbcProperties, log, connection, sqlQueryObject, id, idMappingResolutionBehaviour);
  240.         }else{
  241.             throw new NotFoundException("Entry with id["+id+"] not found");
  242.         }
  243.        
  244.     }
  245.    
  246.     @Override
  247.     public NonNegativeNumber count(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCExpression expression) throws NotImplementedException, ServiceException,Exception {
  248.        
  249.         List<Object> listaQuery = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareCount(jdbcProperties, log, connection, sqlQueryObject, expression,
  250.                                                 this.getPortaDelegataFieldConverter(), PortaDelegata.model());
  251.        
  252.         sqlQueryObject.addSelectCountField(this.getPortaDelegataFieldConverter().toTable(PortaDelegata.model())+".id","tot",true);
  253.        
  254.         joinEngine(expression,sqlQueryObject);
  255.        
  256.         return org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.count(jdbcProperties, log, connection, sqlQueryObject, expression,
  257.                                                                             this.getPortaDelegataFieldConverter(), PortaDelegata.model(),listaQuery);
  258.     }

  259.     @Override
  260.     public InUse inUse(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdPortaDelegata id) throws NotFoundException, NotImplementedException, ServiceException,Exception {
  261.        
  262.         Long id_portaDelegata = this.findIdPortaDelegata(jdbcProperties, log, connection, sqlQueryObject, id, true);
  263.         return this.inUseEngine(jdbcProperties, log, connection, sqlQueryObject, id_portaDelegata);
  264.        
  265.     }

  266.     @Override
  267.     public List<Object> select(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  268.                                                     JDBCPaginatedExpression paginatedExpression, IField field) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  269.         return this.select(jdbcProperties, log, connection, sqlQueryObject,
  270.                                 paginatedExpression, false, field);
  271.     }
  272.    
  273.     @Override
  274.     public List<Object> select(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  275.                                                     JDBCPaginatedExpression paginatedExpression, boolean distinct, IField field) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  276.         List<Map<String,Object>> map =
  277.             this.select(jdbcProperties, log, connection, sqlQueryObject, paginatedExpression, distinct, new IField[]{field});
  278.         return org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.selectSingleObject(map);
  279.     }
  280.    
  281.     @Override
  282.     public List<Map<String,Object>> select(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  283.                                                     JDBCPaginatedExpression paginatedExpression, IField ... field) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  284.         return this.select(jdbcProperties, log, connection, sqlQueryObject,
  285.                                 paginatedExpression, false, field);
  286.     }
  287.    
  288.     @Override
  289.     public List<Map<String,Object>> select(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  290.                                                     JDBCPaginatedExpression paginatedExpression, boolean distinct, IField ... field) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  291.        
  292.         org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.setFields(sqlQueryObject,paginatedExpression,field);
  293.         try{
  294.        
  295.             ISQLQueryObject sqlQueryObjectDistinct =
  296.                         org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareSqlQueryObjectForSelectDistinct(distinct,sqlQueryObject, paginatedExpression, log,
  297.                                                 this.getPortaDelegataFieldConverter(), field);

  298.             return selectEngine(jdbcProperties, log, connection, sqlQueryObject, paginatedExpression, sqlQueryObjectDistinct);
  299.            
  300.         }finally{
  301.             org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.removeFields(sqlQueryObject,paginatedExpression,field);
  302.         }
  303.     }

  304.     @Override
  305.     public Object aggregate(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  306.                                                     JDBCExpression expression, FunctionField functionField) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  307.         Map<String,Object> map =
  308.             this.aggregate(jdbcProperties, log, connection, sqlQueryObject, expression, new FunctionField[]{functionField});
  309.         return org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.selectAggregateObject(map,functionField);
  310.     }
  311.    
  312.     @Override
  313.     public Map<String,Object> aggregate(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  314.                                                     JDBCExpression expression, FunctionField ... functionField) throws ServiceException,NotFoundException,NotImplementedException,Exception {                                                  
  315.        
  316.         org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.setFields(sqlQueryObject,expression,functionField);
  317.         try{
  318.             List<Map<String,Object>> list = selectEngine(jdbcProperties, log, connection, sqlQueryObject, expression);
  319.             return list.get(0);
  320.         }finally{
  321.             org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.removeFields(sqlQueryObject,expression,functionField);
  322.         }
  323.     }

  324.     @Override
  325.     public List<Map<String,Object>> groupBy(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  326.                                                     JDBCExpression expression, FunctionField ... functionField) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  327.        
  328.         if(expression.getGroupByFields().isEmpty()){
  329.             throw new ServiceException("GroupBy conditions not found in expression");
  330.         }
  331.        
  332.         org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.setFields(sqlQueryObject,expression,functionField);
  333.         try{
  334.             return selectEngine(jdbcProperties, log, connection, sqlQueryObject, expression);
  335.         }finally{
  336.             org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.removeFields(sqlQueryObject,expression,functionField);
  337.         }
  338.     }
  339.    

  340.     @Override
  341.     public List<Map<String,Object>> groupBy(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  342.                                                     JDBCPaginatedExpression paginatedExpression, FunctionField ... functionField) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  343.        
  344.         if(paginatedExpression.getGroupByFields().isEmpty()){
  345.             throw new ServiceException("GroupBy conditions not found in expression");
  346.         }
  347.        
  348.         org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.setFields(sqlQueryObject,paginatedExpression,functionField);
  349.         try{
  350.             return selectEngine(jdbcProperties, log, connection, sqlQueryObject, paginatedExpression);
  351.         }finally{
  352.             org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.removeFields(sqlQueryObject,paginatedExpression,functionField);
  353.         }
  354.     }
  355.    
  356.     protected List<Map<String,Object>> selectEngine(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  357.                                                 IExpression expression) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  358.         return selectEngine(jdbcProperties, log, connection, sqlQueryObject, expression, null);
  359.     }
  360.     protected List<Map<String,Object>> selectEngine(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  361.                                                 IExpression expression, ISQLQueryObject sqlQueryObjectDistinct) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  362.        
  363.         List<Object> listaQuery = new ArrayList<>();
  364.         List<JDBCObject> listaParams = new ArrayList<>();
  365.         List<Object> returnField = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareSelect(jdbcProperties, log, connection, sqlQueryObject,
  366.                                 expression, this.getPortaDelegataFieldConverter(), PortaDelegata.model(),
  367.                                 listaQuery,listaParams);
  368.        
  369.         joinEngine(expression,sqlQueryObject);
  370.        
  371.         List<Map<String,Object>> list = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.select(jdbcProperties, log, connection,
  372.                                         org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareSqlQueryObjectForSelectDistinct(sqlQueryObject,sqlQueryObjectDistinct),
  373.                                         expression, this.getPortaDelegataFieldConverter(), PortaDelegata.model(),
  374.                                         listaQuery,listaParams,returnField);
  375.         if(list!=null && !list.isEmpty()){
  376.             return list;
  377.         }
  378.         else{
  379.             throw org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.newNotFoundException();
  380.         }
  381.     }
  382.    
  383.     @Override
  384.     public List<Map<String,Object>> union(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  385.                                                 Union union, UnionExpression ... unionExpression) throws ServiceException,NotFoundException,NotImplementedException,Exception {    
  386.        
  387.         List<ISQLQueryObject> sqlQueryObjectInnerList = new ArrayList<>();
  388.         List<JDBCObject> jdbcObjects = new ArrayList<>();
  389.         List<Class<?>> returnClassTypes = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareUnion(jdbcProperties, log, connection, sqlQueryObject,
  390.                                 this.getPortaDelegataFieldConverter(), PortaDelegata.model(),
  391.                                 sqlQueryObjectInnerList, jdbcObjects, union, unionExpression);
  392.        
  393.         if(unionExpression!=null){
  394.             for (int i = 0; i < unionExpression.length; i++) {
  395.                 UnionExpression ue = unionExpression[i];
  396.                 IExpression expression = ue.getExpression();
  397.                 joinEngine(expression,sqlQueryObjectInnerList.get(i));
  398.             }
  399.         }
  400.        
  401.         List<Map<String,Object>> list = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.union(jdbcProperties, log, connection, sqlQueryObject,
  402.                                         this.getPortaDelegataFieldConverter(), PortaDelegata.model(),
  403.                                         sqlQueryObjectInnerList, jdbcObjects, returnClassTypes, union, unionExpression);
  404.         if(list!=null && !list.isEmpty()){
  405.             return list;
  406.         }
  407.         else{
  408.             throw org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.newNotFoundException();
  409.         }                              
  410.     }
  411.    
  412.     @Override
  413.     public NonNegativeNumber unionCount(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  414.                                                 Union union, UnionExpression ... unionExpression) throws ServiceException,NotFoundException,NotImplementedException,Exception {    
  415.        
  416.         List<ISQLQueryObject> sqlQueryObjectInnerList = new ArrayList<>();
  417.         List<JDBCObject> jdbcObjects = new ArrayList<>();
  418.         List<Class<?>> returnClassTypes = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareUnionCount(jdbcProperties, log, connection, sqlQueryObject,
  419.                                 this.getPortaDelegataFieldConverter(), PortaDelegata.model(),
  420.                                 sqlQueryObjectInnerList, jdbcObjects, union, unionExpression);
  421.        
  422.         if(unionExpression!=null){
  423.             for (int i = 0; i < unionExpression.length; i++) {
  424.                 UnionExpression ue = unionExpression[i];
  425.                 IExpression expression = ue.getExpression();
  426.                 joinEngine(expression,sqlQueryObjectInnerList.get(i));
  427.             }
  428.         }
  429.        
  430.         NonNegativeNumber number = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.unionCount(jdbcProperties, log, connection, sqlQueryObject,
  431.                                         this.getPortaDelegataFieldConverter(), PortaDelegata.model(),
  432.                                         sqlQueryObjectInnerList, jdbcObjects, returnClassTypes, union, unionExpression);
  433.         if(number!=null && number.longValue()>=0){
  434.             return number;
  435.         }
  436.         else{
  437.             throw org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.newNotFoundException();
  438.         }
  439.     }



  440.     // -- ConstructorExpression

  441.     @Override
  442.     public JDBCExpression newExpression(Logger log) throws NotImplementedException, ServiceException {
  443.         try{
  444.             return new JDBCExpression(this.getPortaDelegataFieldConverter());
  445.         }catch(Exception e){
  446.             throw new ServiceException(e);
  447.         }
  448.     }


  449.     @Override
  450.     public JDBCPaginatedExpression newPaginatedExpression(Logger log) throws NotImplementedException, ServiceException {
  451.         try{
  452.             return new JDBCPaginatedExpression(this.getPortaDelegataFieldConverter());
  453.         }catch(Exception e){
  454.             throw new ServiceException(e);
  455.         }
  456.     }
  457.    
  458.     @Override
  459.     public JDBCExpression toExpression(JDBCPaginatedExpression paginatedExpression, Logger log) throws NotImplementedException, ServiceException {
  460.         try{
  461.             return new JDBCExpression(paginatedExpression);
  462.         }catch(Exception e){
  463.             throw new ServiceException(e);
  464.         }
  465.     }

  466.     @Override
  467.     public JDBCPaginatedExpression toPaginatedExpression(JDBCExpression expression, Logger log) throws NotImplementedException, ServiceException {
  468.         try{
  469.             return new JDBCPaginatedExpression(expression);
  470.         }catch(Exception e){
  471.             throw new ServiceException(e);
  472.         }
  473.     }
  474.    
  475.    
  476.    
  477.     // -- DB

  478.     @Override
  479.     public void mappingTableIds(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdPortaDelegata id, PortaDelegata obj) throws NotFoundException,NotImplementedException,ServiceException,Exception{
  480.         _mappingTableIds(jdbcProperties,log,connection,sqlQueryObject,obj,
  481.                 this.get(jdbcProperties,log,connection,sqlQueryObject,id,null));
  482.     }
  483.    
  484.     @Override
  485.     public void mappingTableIds(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId, PortaDelegata obj) throws NotFoundException,NotImplementedException,ServiceException,Exception{
  486.         _mappingTableIds(jdbcProperties,log,connection,sqlQueryObject,obj,
  487.                 this.get(jdbcProperties,log,connection,sqlQueryObject,tableId,null));
  488.     }
  489.     private void _mappingTableIds(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, PortaDelegata obj, PortaDelegata imgSaved) throws NotFoundException,NotImplementedException,ServiceException,Exception{
  490.         if(imgSaved==null){
  491.             return;
  492.         }
  493.         obj.setId(imgSaved.getId());
  494.         if(obj.getIdSoggetto()!=null &&
  495.                 imgSaved.getIdSoggetto()!=null){
  496.             obj.getIdSoggetto().setId(imgSaved.getIdSoggetto().getId());
  497.         }
  498.         if(obj.getPortaDelegataServizioApplicativoList()!=null){
  499.             List<org.openspcoop2.core.commons.search.PortaDelegataServizioApplicativo> listObj_ = obj.getPortaDelegataServizioApplicativoList();
  500.             for(org.openspcoop2.core.commons.search.PortaDelegataServizioApplicativo itemObj_ : listObj_){
  501.                 org.openspcoop2.core.commons.search.PortaDelegataServizioApplicativo itemAlreadySaved_ = null;
  502.                 if(imgSaved.getPortaDelegataServizioApplicativoList()!=null){
  503.                     List<org.openspcoop2.core.commons.search.PortaDelegataServizioApplicativo> listImgSaved_ = imgSaved.getPortaDelegataServizioApplicativoList();
  504.                     for(org.openspcoop2.core.commons.search.PortaDelegataServizioApplicativo itemImgSaved_ : listImgSaved_){
  505.                         boolean objEqualsToImgSaved_ = false;
  506.                         if(itemObj_.getIdServizioApplicativo()!=null && itemObj_.getIdServizioApplicativo().getIdSoggetto()!=null &&
  507.                                 itemImgSaved_.getIdServizioApplicativo()!=null && itemImgSaved_.getIdServizioApplicativo().getIdSoggetto()!=null){
  508.                             objEqualsToImgSaved_ = org.openspcoop2.generic_project.utils.Utilities.equals(itemObj_.getIdServizioApplicativo().getNome(),itemImgSaved_.getIdServizioApplicativo().getNome()) &&
  509.                                                                 org.openspcoop2.generic_project.utils.Utilities.equals(itemObj_.getIdServizioApplicativo().getIdSoggetto().getTipo(),itemImgSaved_.getIdServizioApplicativo().getIdSoggetto().getTipo()) &&
  510.                                                                 org.openspcoop2.generic_project.utils.Utilities.equals(itemObj_.getIdServizioApplicativo().getIdSoggetto().getNome(),itemImgSaved_.getIdServizioApplicativo().getIdSoggetto().getNome());
  511.                         }
  512.                         if(objEqualsToImgSaved_){
  513.                             itemAlreadySaved_=itemImgSaved_;
  514.                             break;
  515.                         }
  516.                     }
  517.                 }
  518.                 if(itemAlreadySaved_!=null){
  519.                     itemObj_.setId(itemAlreadySaved_.getId());
  520.                     if(itemObj_.getIdServizioApplicativo()!=null &&
  521.                             itemAlreadySaved_.getIdServizioApplicativo()!=null){
  522.                         itemObj_.getIdServizioApplicativo().setId(itemAlreadySaved_.getIdServizioApplicativo().getId());
  523.                         if(itemObj_.getIdServizioApplicativo().getIdSoggetto()!=null &&
  524.                                 itemAlreadySaved_.getIdServizioApplicativo().getIdSoggetto()!=null){
  525.                             itemObj_.getIdServizioApplicativo().getIdSoggetto().setId(itemAlreadySaved_.getIdServizioApplicativo().getIdSoggetto().getId());
  526.                         }
  527.                     }
  528.                 }
  529.             }
  530.         }
  531.         if(obj.getPortaDelegataAzioneList()!=null){
  532.             List<org.openspcoop2.core.commons.search.PortaDelegataAzione> listObj_ = obj.getPortaDelegataAzioneList();
  533.             for(org.openspcoop2.core.commons.search.PortaDelegataAzione itemObj_ : listObj_){
  534.                 org.openspcoop2.core.commons.search.PortaDelegataAzione itemAlreadySaved_ = null;
  535.                 if(imgSaved.getPortaDelegataAzioneList()!=null){
  536.                     List<org.openspcoop2.core.commons.search.PortaDelegataAzione> listImgSaved_ = imgSaved.getPortaDelegataAzioneList();
  537.                     for(org.openspcoop2.core.commons.search.PortaDelegataAzione itemImgSaved_ : listImgSaved_){
  538.                         boolean objEqualsToImgSaved_ = false;
  539.                         objEqualsToImgSaved_ = org.openspcoop2.generic_project.utils.Utilities.equals(itemObj_.getNome(),itemImgSaved_.getNome());
  540.                         if(objEqualsToImgSaved_){
  541.                             itemAlreadySaved_=itemImgSaved_;
  542.                             break;
  543.                         }
  544.                     }
  545.                 }
  546.                 if(itemAlreadySaved_!=null){
  547.                     itemObj_.setId(itemAlreadySaved_.getId());
  548.                 }
  549.             }
  550.         }
  551.              
  552.     }
  553.    
  554.     @Override
  555.     public PortaDelegata get(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotFoundException, MultipleResultException, NotImplementedException, ServiceException, Exception {
  556.         return this.getEngine(jdbcProperties, log, connection, sqlQueryObject, Long.valueOf(tableId), idMappingResolutionBehaviour);
  557.     }
  558.    
  559.     private PortaDelegata getEngine(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, Long tableId, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotFoundException, MultipleResultException, NotImplementedException, ServiceException, Exception {
  560.    
  561.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  562.                     new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);
  563.        
  564.         ISQLQueryObject sqlQueryObjectGet = sqlQueryObject.newSQLQueryObject();
  565.                
  566.         PortaDelegata portaDelegata = new PortaDelegata();
  567.        

  568.         // Object portaDelegata
  569.         ISQLQueryObject sqlQueryObjectGet_portaDelegata = sqlQueryObjectGet.newSQLQueryObject();
  570.         sqlQueryObjectGet_portaDelegata.setANDLogicOperator(true);
  571.         sqlQueryObjectGet_portaDelegata.addFromTable(this.getPortaDelegataFieldConverter().toTable(PortaDelegata.model()));
  572.         sqlQueryObjectGet_portaDelegata.addSelectField("id");
  573.         sqlQueryObjectGet_portaDelegata.addSelectField(this.getPortaDelegataFieldConverter().toColumn(PortaDelegata.model().NOME,true));
  574.         sqlQueryObjectGet_portaDelegata.addSelectField(this.getPortaDelegataFieldConverter().toColumn(PortaDelegata.model().STATO,true));
  575.         sqlQueryObjectGet_portaDelegata.addSelectField(this.getPortaDelegataFieldConverter().toColumn(PortaDelegata.model().TIPO_SOGGETTO_EROGATORE,true));
  576.         sqlQueryObjectGet_portaDelegata.addSelectField(this.getPortaDelegataFieldConverter().toColumn(PortaDelegata.model().NOME_SOGGETTO_EROGATORE,true));
  577.         sqlQueryObjectGet_portaDelegata.addSelectField(this.getPortaDelegataFieldConverter().toColumn(PortaDelegata.model().TIPO_SERVIZIO,true));
  578.         sqlQueryObjectGet_portaDelegata.addSelectField(this.getPortaDelegataFieldConverter().toColumn(PortaDelegata.model().NOME_SERVIZIO,true));
  579.         sqlQueryObjectGet_portaDelegata.addSelectField(this.getPortaDelegataFieldConverter().toColumn(PortaDelegata.model().VERSIONE_SERVIZIO,true));
  580.         sqlQueryObjectGet_portaDelegata.addSelectField(this.getPortaDelegataFieldConverter().toColumn(PortaDelegata.model().MODE_AZIONE,true));
  581.         sqlQueryObjectGet_portaDelegata.addSelectField(this.getPortaDelegataFieldConverter().toColumn(PortaDelegata.model().NOME_AZIONE,true));
  582.         sqlQueryObjectGet_portaDelegata.addSelectField(this.getPortaDelegataFieldConverter().toColumn(PortaDelegata.model().NOME_PORTA_DELEGANTE_AZIONE,true));
  583.         sqlQueryObjectGet_portaDelegata.addSelectField(this.getPortaDelegataFieldConverter().toColumn(PortaDelegata.model().CANALE,true));
  584.         sqlQueryObjectGet_portaDelegata.addWhereCondition("id=?");

  585.         // Get portaDelegata
  586.         portaDelegata = (PortaDelegata) jdbcUtilities.executeQuerySingleResult(sqlQueryObjectGet_portaDelegata.createSQLQuery(), jdbcProperties.isShowSql(), PortaDelegata.model(), this.getPortaDelegataFetch(),
  587.             new JDBCObject(tableId,Long.class));


  588.         // Object _portaDelegata_soggetto (recupero id)
  589.         ISQLQueryObject sqlQueryObjectGet_portaDelegata_soggetto_readFkId = sqlQueryObjectGet.newSQLQueryObject();
  590.         sqlQueryObjectGet_portaDelegata_soggetto_readFkId.addFromTable(this.getPortaDelegataFieldConverter().toTable(org.openspcoop2.core.commons.search.PortaDelegata.model()));
  591.         sqlQueryObjectGet_portaDelegata_soggetto_readFkId.addSelectField("id_soggetto");
  592.         sqlQueryObjectGet_portaDelegata_soggetto_readFkId.addWhereCondition("id=?");
  593.         sqlQueryObjectGet_portaDelegata_soggetto_readFkId.setANDLogicOperator(true);
  594.         Long idFK_portaDelegata_soggetto = (Long) jdbcUtilities.executeQuerySingleResult(sqlQueryObjectGet_portaDelegata_soggetto_readFkId.createSQLQuery(), jdbcProperties.isShowSql(),Long.class,
  595.                 new JDBCObject(portaDelegata.getId(),Long.class));
  596.        
  597.         // Object _portaDelegata_soggetto
  598.         ISQLQueryObject sqlQueryObjectGet_portaDelegata_soggetto = sqlQueryObjectGet.newSQLQueryObject();
  599.         sqlQueryObjectGet_portaDelegata_soggetto.addFromTable("soggetti");
  600.         sqlQueryObjectGet_portaDelegata_soggetto.addSelectField("tipo_soggetto");
  601.         sqlQueryObjectGet_portaDelegata_soggetto.addSelectField("nome_soggetto");
  602.         sqlQueryObjectGet_portaDelegata_soggetto.setANDLogicOperator(true);
  603.         sqlQueryObjectGet_portaDelegata_soggetto.addWhereCondition("id=?");

  604.         // Recupero _portaDelegata_soggetto
  605.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject [] searchParams_portaDelegata_soggetto = new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject [] {
  606.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(idFK_portaDelegata_soggetto,Long.class)
  607.         };
  608.         List<Class<?>> listaFieldIdReturnType_portaDelegata_soggetto = new ArrayList<Class<?>>();
  609.         listaFieldIdReturnType_portaDelegata_soggetto.add(String.class);
  610.         listaFieldIdReturnType_portaDelegata_soggetto.add(String.class);
  611.         List<Object> listaFieldId_portaDelegata_soggetto = jdbcUtilities.executeQuerySingleResult(sqlQueryObjectGet_portaDelegata_soggetto.createSQLQuery(), jdbcProperties.isShowSql(),
  612.                 listaFieldIdReturnType_portaDelegata_soggetto, searchParams_portaDelegata_soggetto);
  613.         IdSoggetto idSoggetto = new IdSoggetto();
  614.         idSoggetto.setTipo((String)listaFieldId_portaDelegata_soggetto.get(0));
  615.         idSoggetto.setNome((String)listaFieldId_portaDelegata_soggetto.get(1));
  616.         portaDelegata.setIdSoggetto(idSoggetto);


  617.         // Object portaDelegata_portaDelegataServizioApplicativo
  618.         ISQLQueryObject sqlQueryObjectGet_portaDelegata_portaDelegataServizioApplicativo = sqlQueryObjectGet.newSQLQueryObject();
  619.         sqlQueryObjectGet_portaDelegata_portaDelegataServizioApplicativo.setANDLogicOperator(true);
  620.         sqlQueryObjectGet_portaDelegata_portaDelegataServizioApplicativo.addFromTable(this.getPortaDelegataFieldConverter().toTable(PortaDelegata.model().PORTA_DELEGATA_SERVIZIO_APPLICATIVO));
  621.         sqlQueryObjectGet_portaDelegata_portaDelegataServizioApplicativo.addSelectField("id");
  622.         sqlQueryObjectGet_portaDelegata_portaDelegataServizioApplicativo.addWhereCondition("id_porta=?");

  623.         // Get portaDelegata_portaDelegataServizioApplicativo
  624.         java.util.List<Object> portaDelegata_portaDelegataServizioApplicativo_list = jdbcUtilities.executeQuery(sqlQueryObjectGet_portaDelegata_portaDelegataServizioApplicativo.createSQLQuery(), jdbcProperties.isShowSql(), PortaDelegata.model().PORTA_DELEGATA_SERVIZIO_APPLICATIVO, this.getPortaDelegataFetch(),
  625.             new JDBCObject(portaDelegata.getId(),Long.class));

  626.         if(portaDelegata_portaDelegataServizioApplicativo_list != null) {
  627.             for (Object portaDelegata_portaDelegataServizioApplicativo_object: portaDelegata_portaDelegataServizioApplicativo_list) {
  628.                 PortaDelegataServizioApplicativo portaDelegata_portaDelegataServizioApplicativo = (PortaDelegataServizioApplicativo) portaDelegata_portaDelegataServizioApplicativo_object;


  629.                 // Object _portaDelegata_portaDelegataServizioApplicativo_servizioApplicativo (recupero id)
  630.                 ISQLQueryObject sqlQueryObjectGet_portaDelegata_portaDelegataServizioApplicativo_servizioApplicativo_readFkId = sqlQueryObjectGet.newSQLQueryObject();
  631.                 sqlQueryObjectGet_portaDelegata_portaDelegataServizioApplicativo_servizioApplicativo_readFkId.addFromTable(this.getPortaDelegataFieldConverter().toTable(org.openspcoop2.core.commons.search.PortaDelegata.model().PORTA_DELEGATA_SERVIZIO_APPLICATIVO));
  632.                 sqlQueryObjectGet_portaDelegata_portaDelegataServizioApplicativo_servizioApplicativo_readFkId.addSelectField("id_servizio_applicativo");
  633.                 sqlQueryObjectGet_portaDelegata_portaDelegataServizioApplicativo_servizioApplicativo_readFkId.addWhereCondition("id=?");
  634.                 sqlQueryObjectGet_portaDelegata_portaDelegataServizioApplicativo_servizioApplicativo_readFkId.setANDLogicOperator(true);
  635.                 Long idFK_portaDelegata_portaDelegataServizioApplicativo_servizioApplicativo = (Long) jdbcUtilities.executeQuerySingleResult(sqlQueryObjectGet_portaDelegata_portaDelegataServizioApplicativo_servizioApplicativo_readFkId.createSQLQuery(), jdbcProperties.isShowSql(),Long.class,
  636.                         new JDBCObject(portaDelegata_portaDelegataServizioApplicativo.getId(),Long.class));
  637.                
  638.                 // Object _portaDelegata_portaDelegataServizioApplicativo_servizioApplicativo
  639.                 ISQLQueryObject sqlQueryObjectGet_portaDelegata_portaDelegataServizioApplicativo_servizioApplicativo = sqlQueryObjectGet.newSQLQueryObject();
  640.                 sqlQueryObjectGet_portaDelegata_portaDelegataServizioApplicativo_servizioApplicativo.addFromTable("servizi_applicativi");
  641.                 sqlQueryObjectGet_portaDelegata_portaDelegataServizioApplicativo_servizioApplicativo.addSelectField("nome");
  642.                 sqlQueryObjectGet_portaDelegata_portaDelegataServizioApplicativo_servizioApplicativo.addSelectField("id_soggetto");
  643.                 sqlQueryObjectGet_portaDelegata_portaDelegataServizioApplicativo_servizioApplicativo.setANDLogicOperator(true);
  644.                 sqlQueryObjectGet_portaDelegata_portaDelegataServizioApplicativo_servizioApplicativo.addWhereCondition("id=?");

  645.                 // Recupero _portaDelegata_portaDelegataServizioApplicativo_servizioApplicativo
  646.                 org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject [] searchParams_portaDelegata_portaDelegataServizioApplicativo_servizioApplicativo = new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject [] {
  647.                     new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(idFK_portaDelegata_portaDelegataServizioApplicativo_servizioApplicativo,Long.class)
  648.                 };
  649.                 List<Class<?>> listaFieldIdReturnType_portaDelegata_portaDelegataServizioApplicativo_servizioApplicativo = new ArrayList<Class<?>>();
  650.                 listaFieldIdReturnType_portaDelegata_portaDelegataServizioApplicativo_servizioApplicativo.add(String.class);
  651.                 listaFieldIdReturnType_portaDelegata_portaDelegataServizioApplicativo_servizioApplicativo.add(Long.class);
  652.                 List<Object> listaFieldId_portaDelegata_portaDelegataServizioApplicativo_servizioApplicativo = jdbcUtilities.executeQuerySingleResult(sqlQueryObjectGet_portaDelegata_portaDelegataServizioApplicativo_servizioApplicativo.createSQLQuery(), jdbcProperties.isShowSql(),
  653.                         listaFieldIdReturnType_portaDelegata_portaDelegataServizioApplicativo_servizioApplicativo, searchParams_portaDelegata_portaDelegataServizioApplicativo_servizioApplicativo);
  654.                 IdServizioApplicativo idServizioApplicativo = new IdServizioApplicativo();
  655.                 idServizioApplicativo.setNome((String)listaFieldId_portaDelegata_portaDelegataServizioApplicativo_servizioApplicativo.get(0));
  656.                 Long idSoggettoLong = (Long) listaFieldId_portaDelegata_portaDelegataServizioApplicativo_servizioApplicativo.get(1);
  657.                 IdSoggetto idSoggettoSA = this.jdbcServiceManager.getSoggettoServiceSearch().convertToId(
  658.                         ((IDBSoggettoServiceSearch)this.jdbcServiceManager.getSoggettoServiceSearch()).get(idSoggettoLong)
  659.                         );
  660.                 idServizioApplicativo.setIdSoggetto(idSoggettoSA);
  661.                 portaDelegata_portaDelegataServizioApplicativo.setIdServizioApplicativo(idServizioApplicativo);
  662.                
  663.                 portaDelegata.addPortaDelegataServizioApplicativo(portaDelegata_portaDelegataServizioApplicativo);
  664.             }
  665.         }

  666.         // Object portaDelegata_portaDelegataAzione
  667.         ISQLQueryObject sqlQueryObjectGet_portaDelegata_portaDelegataAzione = sqlQueryObjectGet.newSQLQueryObject();
  668.         sqlQueryObjectGet_portaDelegata_portaDelegataAzione.setANDLogicOperator(true);
  669.         sqlQueryObjectGet_portaDelegata_portaDelegataAzione.addFromTable(this.getPortaDelegataFieldConverter().toTable(PortaDelegata.model().PORTA_DELEGATA_AZIONE));
  670.         sqlQueryObjectGet_portaDelegata_portaDelegataAzione.addSelectField("id");
  671.         sqlQueryObjectGet_portaDelegata_portaDelegataAzione.addSelectField(this.getPortaDelegataFieldConverter().toColumn(PortaDelegata.model().PORTA_DELEGATA_AZIONE.NOME,true));
  672.         sqlQueryObjectGet_portaDelegata_portaDelegataAzione.addWhereCondition("id_porta=?");

  673.         // Get portaDelegata_portaDelegataAzione
  674.         java.util.List<Object> portaDelegata_portaDelegataAzione_list = jdbcUtilities.executeQuery(sqlQueryObjectGet_portaDelegata_portaDelegataAzione.createSQLQuery(), jdbcProperties.isShowSql(), PortaDelegata.model().PORTA_DELEGATA_AZIONE, this.getPortaDelegataFetch(),
  675.             new JDBCObject(portaDelegata.getId(),Long.class));

  676.         if(portaDelegata_portaDelegataAzione_list != null) {
  677.             for (Object portaDelegata_portaDelegataAzione_object: portaDelegata_portaDelegataAzione_list) {
  678.                 PortaDelegataAzione portaDelegata_portaDelegataAzione = (PortaDelegataAzione) portaDelegata_portaDelegataAzione_object;


  679.                 portaDelegata.addPortaDelegataAzione(portaDelegata_portaDelegataAzione);
  680.             }
  681.         }      
  682.        
  683.         return portaDelegata;  
  684.    
  685.     }
  686.    
  687.     @Override
  688.     public boolean exists(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId) throws MultipleResultException, NotImplementedException, ServiceException, Exception {
  689.         return this._exists(jdbcProperties, log, connection, sqlQueryObject, Long.valueOf(tableId));
  690.     }
  691.    
  692.     private boolean _exists(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, Long tableId) throws MultipleResultException, NotImplementedException, ServiceException, Exception {
  693.    
  694.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  695.                     new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);
  696.                
  697.         boolean existsPortaDelegata = false;

  698.         sqlQueryObject = sqlQueryObject.newSQLQueryObject();
  699.         sqlQueryObject.setANDLogicOperator(true);

  700.         sqlQueryObject.addFromTable(this.getPortaDelegataFieldConverter().toTable(PortaDelegata.model()));
  701.         sqlQueryObject.addSelectField(this.getPortaDelegataFieldConverter().toColumn(PortaDelegata.model().NOME,true));
  702.         sqlQueryObject.addWhereCondition("id=?");


  703.         // Exists portaDelegata
  704.         existsPortaDelegata = jdbcUtilities.exists(sqlQueryObject.createSQLQuery(), jdbcProperties.isShowSql(),
  705.             new JDBCObject(tableId,Long.class));

  706.        
  707.         return existsPortaDelegata;
  708.    
  709.     }
  710.    
  711.     private void joinEngine(IExpression expression, ISQLQueryObject sqlQueryObject) throws NotImplementedException, ServiceException, Exception{
  712.    
  713.         if(expression.inUseModel(PortaDelegata.model().ID_SOGGETTO,false)){
  714.             String tableName1 = this.getPortaDelegataFieldConverter().toAliasTable(PortaDelegata.model());
  715.             String tableName2 = this.getPortaDelegataFieldConverter().toAliasTable(PortaDelegata.model().ID_SOGGETTO);
  716.             sqlQueryObject.addWhereCondition(tableName1+".id_soggetto="+tableName2+".id");
  717.         }
  718.         if(expression.inUseModel(PortaDelegata.model().PORTA_DELEGATA_SERVIZIO_APPLICATIVO,false)){
  719.             String tableName1 = this.getPortaDelegataFieldConverter().toAliasTable(PortaDelegata.model());
  720.             String tableName2 = this.getPortaDelegataFieldConverter().toAliasTable(PortaDelegata.model().PORTA_DELEGATA_SERVIZIO_APPLICATIVO);
  721.             sqlQueryObject.addWhereCondition(tableName1+".id="+tableName2+".id_porta");
  722.         }
  723.         if(expression.inUseModel(PortaDelegata.model().PORTA_DELEGATA_SERVIZIO_APPLICATIVO.ID_SERVIZIO_APPLICATIVO,false)){
  724.             String tableName1 = this.getPortaDelegataFieldConverter().toAliasTable(PortaDelegata.model().PORTA_DELEGATA_SERVIZIO_APPLICATIVO);
  725.             String tableName2 = this.getPortaDelegataFieldConverter().toAliasTable(PortaDelegata.model().PORTA_DELEGATA_SERVIZIO_APPLICATIVO.ID_SERVIZIO_APPLICATIVO);
  726.             sqlQueryObject.addWhereCondition(tableName1+".id_servizio_applicativo="+tableName2+".id");
  727.         }
  728.         if(expression.inUseModel(PortaDelegata.model().PORTA_DELEGATA_SERVIZIO_APPLICATIVO.ID_SERVIZIO_APPLICATIVO.ID_SOGGETTO,false)){
  729.             String tableName1 = this.getPortaDelegataFieldConverter().toAliasTable(PortaDelegata.model().PORTA_DELEGATA_SERVIZIO_APPLICATIVO.ID_SERVIZIO_APPLICATIVO);
  730.             String tableName2 = this.getPortaDelegataFieldConverter().toAliasTable(PortaDelegata.model().PORTA_DELEGATA_SERVIZIO_APPLICATIVO.ID_SERVIZIO_APPLICATIVO.ID_SOGGETTO);
  731.             sqlQueryObject.addWhereCondition(tableName1+".id_soggetto="+tableName2+".id");
  732.         }
  733.         if(expression.inUseModel(PortaDelegata.model().PORTA_DELEGATA_AZIONE,false)){
  734.             String tableName1 = this.getPortaDelegataFieldConverter().toAliasTable(PortaDelegata.model());
  735.             String tableName2 = this.getPortaDelegataFieldConverter().toAliasTable(PortaDelegata.model().PORTA_DELEGATA_AZIONE);
  736.             sqlQueryObject.addWhereCondition(tableName1+".id="+tableName2+".id_porta");
  737.         }
  738.        
  739.        
  740.         boolean addFromPDSA = false;
  741.         if(expression.inUseModel(PortaDelegata.model().PORTA_DELEGATA_SERVIZIO_APPLICATIVO.ID_SERVIZIO_APPLICATIVO,false)){
  742.             if(expression.inUseModel(PortaDelegata.model().PORTA_DELEGATA_SERVIZIO_APPLICATIVO,false)==false){
  743.                
  744.                 sqlQueryObject.addFromTable(this.getPortaDelegataFieldConverter().toTable(PortaDelegata.model().PORTA_DELEGATA_SERVIZIO_APPLICATIVO));
  745.                
  746.                 String tableName1 = this.getPortaDelegataFieldConverter().toAliasTable(PortaDelegata.model());
  747.                 String tableName2 = this.getPortaDelegataFieldConverter().toAliasTable(PortaDelegata.model().PORTA_DELEGATA_SERVIZIO_APPLICATIVO);
  748.                 try{
  749.                     sqlQueryObject.addWhereCondition(tableName1+".id="+tableName2+".id_porta");
  750.                 }catch(Exception e){
  751.                     // exception se gia' esiste
  752.                 }
  753.                
  754.                 addFromPDSA = true;
  755.             }
  756.         }
  757.         if(expression.inUseModel(PortaDelegata.model().PORTA_DELEGATA_SERVIZIO_APPLICATIVO.ID_SERVIZIO_APPLICATIVO.ID_SOGGETTO,false)){
  758.             if(expression.inUseModel(PortaDelegata.model().PORTA_DELEGATA_SERVIZIO_APPLICATIVO.ID_SERVIZIO_APPLICATIVO,false)==false){
  759.                
  760.                 sqlQueryObject.addFromTable(this.getPortaDelegataFieldConverter().toTable(PortaDelegata.model().PORTA_DELEGATA_SERVIZIO_APPLICATIVO.ID_SERVIZIO_APPLICATIVO));
  761.                
  762.                 String tableName1 = this.getPortaDelegataFieldConverter().toAliasTable(PortaDelegata.model().PORTA_DELEGATA_SERVIZIO_APPLICATIVO);
  763.                 String tableName2 = this.getPortaDelegataFieldConverter().toAliasTable(PortaDelegata.model().PORTA_DELEGATA_SERVIZIO_APPLICATIVO.ID_SERVIZIO_APPLICATIVO);
  764.                 try{
  765.                     sqlQueryObject.addWhereCondition(tableName1+".id_servizio_applicativo="+tableName2+".id");
  766.                 }catch(Exception e){
  767.                     // exception se gia' esiste
  768.                 }
  769.            
  770.             }
  771.             if(addFromPDSA==false){
  772.                 sqlQueryObject.addFromTable(this.getPortaDelegataFieldConverter().toTable(PortaDelegata.model().PORTA_DELEGATA_SERVIZIO_APPLICATIVO));
  773.             }
  774.         }
  775.        
  776.     }
  777.    
  778.     protected java.util.List<Object> getRootTablePrimaryKeyValuesEngine(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdPortaDelegata id) throws NotFoundException, ServiceException, NotImplementedException, Exception{
  779.         // Identificativi
  780.         java.util.List<Object> rootTableIdValues = new java.util.ArrayList<>();
  781.         Long longId = this.findIdPortaDelegata(jdbcProperties, log, connection, sqlQueryObject.newSQLQueryObject(), id, true);
  782.         rootTableIdValues.add(longId);        
  783.         return rootTableIdValues;
  784.     }
  785.    
  786.     protected Map<String, List<IField>> getMapTableToPKColumnEngine() throws NotImplementedException, Exception{
  787.    
  788.         PortaDelegataFieldConverter converter = this.getPortaDelegataFieldConverter();
  789.         Map<String, List<IField>> mapTableToPKColumn = new java.util.HashMap<>();
  790.         UtilsTemplate<IField> utilities = new UtilsTemplate<>();

  791.         // PortaDelegata.model()
  792.         mapTableToPKColumn.put(converter.toTable(PortaDelegata.model()),
  793.             utilities.newList(
  794.                 new CustomField("id", Long.class, "id", converter.toTable(PortaDelegata.model()))
  795.             ));

  796.         // PortaDelegata.model().ID_SOGGETTO
  797.         mapTableToPKColumn.put(converter.toTable(PortaDelegata.model().ID_SOGGETTO),
  798.             utilities.newList(
  799.                 new CustomField("id", Long.class, "id", converter.toTable(PortaDelegata.model().ID_SOGGETTO))
  800.             ));

  801.         // PortaDelegata.model().PORTA_DELEGATA_SERVIZIO_APPLICATIVO
  802.         mapTableToPKColumn.put(converter.toTable(PortaDelegata.model().PORTA_DELEGATA_SERVIZIO_APPLICATIVO),
  803.             utilities.newList(
  804.                 new CustomField("id", Long.class, "id", converter.toTable(PortaDelegata.model().PORTA_DELEGATA_SERVIZIO_APPLICATIVO))
  805.             ));

  806.         // PortaDelegata.model().PORTA_DELEGATA_SERVIZIO_APPLICATIVO.ID_SERVIZIO_APPLICATIVO
  807.         mapTableToPKColumn.put(converter.toTable(PortaDelegata.model().PORTA_DELEGATA_SERVIZIO_APPLICATIVO.ID_SERVIZIO_APPLICATIVO),
  808.             utilities.newList(
  809.                 new CustomField("id", Long.class, "id", converter.toTable(PortaDelegata.model().PORTA_DELEGATA_SERVIZIO_APPLICATIVO.ID_SERVIZIO_APPLICATIVO))
  810.             ));

  811.         // PortaDelegata.model().PORTA_DELEGATA_SERVIZIO_APPLICATIVO.ID_SERVIZIO_APPLICATIVO.ID_SOGGETTO
  812.         mapTableToPKColumn.put(converter.toTable(PortaDelegata.model().PORTA_DELEGATA_SERVIZIO_APPLICATIVO.ID_SERVIZIO_APPLICATIVO.ID_SOGGETTO),
  813.             utilities.newList(
  814.                 new CustomField("id", Long.class, "id", converter.toTable(PortaDelegata.model().PORTA_DELEGATA_SERVIZIO_APPLICATIVO.ID_SERVIZIO_APPLICATIVO.ID_SOGGETTO))
  815.             ));

  816.         // PortaDelegata.model().PORTA_DELEGATA_AZIONE
  817.         mapTableToPKColumn.put(converter.toTable(PortaDelegata.model().PORTA_DELEGATA_AZIONE),
  818.             utilities.newList(
  819.                 new CustomField("id", Long.class, "id", converter.toTable(PortaDelegata.model().PORTA_DELEGATA_AZIONE))
  820.             ));
  821.        
  822.         return mapTableToPKColumn;      
  823.     }
  824.    
  825.     @Override
  826.     public List<Long> findAllTableIds(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCPaginatedExpression paginatedExpression) throws ServiceException, NotImplementedException, Exception {
  827.        
  828.         List<Long> list = new ArrayList<Long>();

  829.         sqlQueryObject.setSelectDistinct(true);
  830.         sqlQueryObject.setANDLogicOperator(true);
  831.         sqlQueryObject.addSelectField(this.getPortaDelegataFieldConverter().toTable(PortaDelegata.model())+".id");
  832.         Class<?> objectIdClass = Long.class;
  833.        
  834.         List<Object> listaQuery = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareFindAll(jdbcProperties, log, connection, sqlQueryObject, paginatedExpression,
  835.                                                 this.getPortaDelegataFieldConverter(), PortaDelegata.model());
  836.        
  837.         joinEngine(paginatedExpression,sqlQueryObject);
  838.        
  839.         List<Object> listObjects = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.findAll(jdbcProperties, log, connection, sqlQueryObject, paginatedExpression,
  840.                                                                             this.getPortaDelegataFieldConverter(), PortaDelegata.model(), objectIdClass, listaQuery);
  841.         for(Object object: listObjects) {
  842.             list.add((Long)object);
  843.         }

  844.         return list;
  845.        
  846.     }
  847.    
  848.     @Override
  849.     public long findTableId(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCExpression expression) throws ServiceException, NotFoundException, MultipleResultException, NotImplementedException, Exception {
  850.    
  851.         sqlQueryObject.setSelectDistinct(true);
  852.         sqlQueryObject.setANDLogicOperator(true);
  853.         sqlQueryObject.addSelectField(this.getPortaDelegataFieldConverter().toTable(PortaDelegata.model())+".id");
  854.         Class<?> objectIdClass = Long.class;
  855.        
  856.         List<Object> listaQuery = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareFind(jdbcProperties, log, connection, sqlQueryObject, expression,
  857.                                                 this.getPortaDelegataFieldConverter(), PortaDelegata.model());
  858.        
  859.         joinEngine(expression,sqlQueryObject);

  860.         Object res = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.find(jdbcProperties, log, connection, sqlQueryObject, expression,
  861.                                                         this.getPortaDelegataFieldConverter(), PortaDelegata.model(), objectIdClass, listaQuery);
  862.         if(res!=null && (((Long) res).longValue()>0) ){
  863.             return ((Long) res).longValue();
  864.         }
  865.         else{
  866.             throw org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.newNotFoundException();
  867.         }
  868.        
  869.     }

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

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

  875.         InUse inUse = new InUse();
  876.         inUse.setInUse(false);
  877.        
  878.         /*
  879.          * TODO: implement code that checks whether the object identified by the id parameter is used by other objects
  880.         */
  881.        
  882.         // Delete this line when you have implemented the method
  883.         int throwNotImplemented = 1;
  884.         if(throwNotImplemented==1){
  885.                 throw new NotImplementedException("NotImplemented");
  886.         }
  887.         // Delete this line when you have implemented the method

  888.         return inUse;

  889.     }
  890.    
  891.     @Override
  892.     public IdPortaDelegata findId(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId, boolean throwNotFound)
  893.             throws NotFoundException, ServiceException, NotImplementedException, Exception {
  894.        
  895.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  896.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);

  897.         ISQLQueryObject sqlQueryObjectGet = sqlQueryObject.newSQLQueryObject();            

  898.         // Object _portaDelegata
  899.         sqlQueryObjectGet.addFromTable(this.getPortaDelegataFieldConverter().toTable(PortaDelegata.model()));
  900.         sqlQueryObjectGet.addSelectField(this.getPortaDelegataFieldConverter().toColumn(PortaDelegata.model().NOME,true));
  901.         sqlQueryObjectGet.setANDLogicOperator(true);
  902.         sqlQueryObjectGet.addWhereCondition("id=?");

  903.         // Recupero _portaDelegata
  904.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject [] searchParams_portaDelegata = new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject [] {
  905.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(tableId,Long.class)
  906.         };
  907.         List<Class<?>> listaFieldIdReturnType_portaDelegata = new ArrayList<Class<?>>();
  908.         listaFieldIdReturnType_portaDelegata.add(String.class);
  909.         org.openspcoop2.core.commons.search.IdPortaDelegata id_portaDelegata = null;
  910.         List<Object> listaFieldId_portaDelegata = jdbcUtilities.executeQuerySingleResult(sqlQueryObjectGet.createSQLQuery(), jdbcProperties.isShowSql(),
  911.                 listaFieldIdReturnType_portaDelegata, searchParams_portaDelegata);
  912.         if(listaFieldId_portaDelegata==null || listaFieldId_portaDelegata.size()<=0){
  913.             if(throwNotFound){
  914.                 throw org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.newNotFoundException();
  915.             }
  916.         }
  917.         else{
  918.             // set _portaDelegata
  919.             id_portaDelegata = new org.openspcoop2.core.commons.search.IdPortaDelegata();
  920.             id_portaDelegata.setNome((String)listaFieldId_portaDelegata.get(0));
  921.            
  922.         }
  923.        
  924.         return id_portaDelegata;
  925.        
  926.     }

  927.     @Override
  928.     public Long findTableId(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdPortaDelegata id, boolean throwNotFound)
  929.             throws NotFoundException, ServiceException, NotImplementedException, Exception {
  930.    
  931.         return this.findIdPortaDelegata(jdbcProperties,log,connection,sqlQueryObject,id,throwNotFound);
  932.            
  933.     }
  934.    
  935.     @Override
  936.     public List<List<Object>> nativeQuery(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  937.                                             String sql,List<Class<?>> returnClassTypes,Object ... param) throws ServiceException,NotFoundException,NotImplementedException,Exception{
  938.        
  939.         return org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.nativeQuery(jdbcProperties, log, connection, sqlQueryObject,
  940.                                                                                             sql,returnClassTypes,param);
  941.                                                        
  942.     }
  943.    
  944.     protected Long findIdPortaDelegata(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdPortaDelegata id, boolean throwNotFound) throws NotFoundException, ServiceException, NotImplementedException, Exception {

  945.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  946.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);

  947.         ISQLQueryObject sqlQueryObjectGet = sqlQueryObject.newSQLQueryObject();


  948.         if(id==null){
  949.             throw new ServiceException("Id not defined");
  950.         }
  951.         if(id.getNome()==null){
  952.             throw new ServiceException("Id.nome not defined");
  953.         }

  954.         // Object _portaDelegata
  955.         sqlQueryObjectGet.addFromTable(this.getPortaDelegataFieldConverter().toTable(PortaDelegata.model()));
  956.         sqlQueryObjectGet.addSelectField("id");
  957.         // Devono essere mappati nella where condition i metodi dell'oggetto id.getXXX
  958.         sqlQueryObjectGet.setANDLogicOperator(true);
  959.         sqlQueryObjectGet.setSelectDistinct(true);
  960.         sqlQueryObjectGet.addWhereCondition(this.getPortaDelegataFieldConverter().toColumn(PortaDelegata.model().NOME,true)+"=?");

  961.         // Recupero _portaDelegata
  962.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject [] searchParams_portaDelegata = new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject [] {
  963.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(id.getNome(),String.class)
  964.         };
  965.         Long id_portaDelegata = null;
  966.         try{
  967.             id_portaDelegata = (Long) jdbcUtilities.executeQuerySingleResult(sqlQueryObjectGet.createSQLQuery(), jdbcProperties.isShowSql(),
  968.                         Long.class, searchParams_portaDelegata);
  969.         }catch(NotFoundException notFound){
  970.             if(throwNotFound){
  971.                 throw new NotFoundException(notFound);
  972.             }
  973.         }
  974.         if(id_portaDelegata==null || id_portaDelegata<=0){
  975.             if(throwNotFound){
  976.                 throw org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.newNotFoundException();
  977.             }
  978.         }
  979.        
  980.         return id_portaDelegata;
  981.     }
  982. }