JDBCAccordoServizioParteComuneServiceSearchImpl.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.util.List;
  22. import java.util.ArrayList;
  23. import java.util.Map;

  24. import java.sql.Connection;

  25. import org.slf4j.Logger;

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

  27. import org.openspcoop2.generic_project.expression.impl.sql.ISQLFieldConverter;
  28. import org.openspcoop2.generic_project.dao.jdbc.utils.IJDBCFetch;
  29. import org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject;
  30. import org.openspcoop2.generic_project.dao.jdbc.IJDBCServiceSearchWithId;
  31. import org.openspcoop2.core.commons.search.IdAccordoServizioParteComune;
  32. import org.openspcoop2.core.commons.search.IdSoggetto;
  33. import org.openspcoop2.generic_project.utils.UtilsTemplate;
  34. import org.openspcoop2.generic_project.beans.CustomField;
  35. import org.openspcoop2.generic_project.beans.InUse;
  36. import org.openspcoop2.generic_project.beans.IField;
  37. import org.openspcoop2.generic_project.beans.NonNegativeNumber;
  38. import org.openspcoop2.generic_project.beans.UnionExpression;
  39. import org.openspcoop2.generic_project.beans.Union;
  40. import org.openspcoop2.generic_project.beans.FunctionField;
  41. import org.openspcoop2.generic_project.exception.MultipleResultException;
  42. import org.openspcoop2.generic_project.exception.NotFoundException;
  43. import org.openspcoop2.generic_project.exception.NotImplementedException;
  44. import org.openspcoop2.generic_project.exception.ServiceException;
  45. import org.openspcoop2.generic_project.expression.IExpression;
  46. import org.openspcoop2.generic_project.dao.jdbc.JDBCExpression;
  47. import org.openspcoop2.generic_project.dao.jdbc.JDBCPaginatedExpression;

  48. import org.openspcoop2.generic_project.dao.jdbc.JDBCServiceManagerProperties;
  49. import org.openspcoop2.core.commons.search.dao.jdbc.converter.AccordoServizioParteComuneFieldConverter;
  50. import org.openspcoop2.core.commons.search.dao.jdbc.fetch.AccordoServizioParteComuneFetch;
  51. import org.openspcoop2.core.commons.search.dao.IDBSoggettoServiceSearch;
  52. import org.openspcoop2.core.commons.search.AccordoServizioParteComune;
  53. import org.openspcoop2.core.commons.search.AccordoServizioParteComuneAzione;
  54. import org.openspcoop2.core.commons.search.AccordoServizioParteComuneGruppo;
  55. import org.openspcoop2.core.commons.search.PortType;
  56. import org.openspcoop2.core.commons.search.Soggetto;
  57. import org.openspcoop2.core.commons.search.Resource;
  58. import org.openspcoop2.core.commons.search.Operation;

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

  67.     private AccordoServizioParteComuneFieldConverter _accordoServizioParteComuneFieldConverter = null;
  68.     public AccordoServizioParteComuneFieldConverter getAccordoServizioParteComuneFieldConverter() {
  69.         if(this._accordoServizioParteComuneFieldConverter==null){
  70.             this._accordoServizioParteComuneFieldConverter = new AccordoServizioParteComuneFieldConverter(this.jdbcServiceManager.getJdbcProperties().getDatabaseType());
  71.         }      
  72.         return this._accordoServizioParteComuneFieldConverter;
  73.     }
  74.     @Override
  75.     public ISQLFieldConverter getFieldConverter() {
  76.         return this.getAccordoServizioParteComuneFieldConverter();
  77.     }
  78.    
  79.     private AccordoServizioParteComuneFetch accordoServizioParteComuneFetch = new AccordoServizioParteComuneFetch();
  80.     public AccordoServizioParteComuneFetch getAccordoServizioParteComuneFetch() {
  81.         return this.accordoServizioParteComuneFetch;
  82.     }
  83.     @Override
  84.     public IJDBCFetch getFetch() {
  85.         return getAccordoServizioParteComuneFetch();
  86.     }
  87.    
  88.    
  89.     private JDBCServiceManager jdbcServiceManager = null;

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

  103.     @Override
  104.     public IdAccordoServizioParteComune convertToId(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, AccordoServizioParteComune accordoServizioParteComune) throws NotImplementedException, ServiceException, Exception{
  105.    
  106.         IdAccordoServizioParteComune idAccordoServizioParteComune = new IdAccordoServizioParteComune();
  107.         idAccordoServizioParteComune.setIdSoggetto(accordoServizioParteComune.getIdReferente());
  108.         idAccordoServizioParteComune.setNome(accordoServizioParteComune.getNome());
  109.         idAccordoServizioParteComune.setVersione(accordoServizioParteComune.getVersione());
  110.        
  111.         idAccordoServizioParteComune.setServiceBinding(accordoServizioParteComune.getServiceBinding());
  112.        
  113.         return idAccordoServizioParteComune;

  114.     }
  115.    
  116.     @Override
  117.     public AccordoServizioParteComune get(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdAccordoServizioParteComune id, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotFoundException, MultipleResultException, NotImplementedException, ServiceException,Exception {
  118.         Long id_accordoServizioParteComune = ( (id!=null && id.getId()!=null && id.getId()>0) ? id.getId() : this.findIdAccordoServizioParteComune(jdbcProperties, log, connection, sqlQueryObject, id, true));
  119.         return this.getEngine(jdbcProperties, log, connection, sqlQueryObject, id_accordoServizioParteComune,idMappingResolutionBehaviour);
  120.        
  121.        
  122.     }
  123.    
  124.     @Override
  125.     public boolean exists(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdAccordoServizioParteComune id) throws MultipleResultException, NotImplementedException, ServiceException,Exception {

  126.         Long id_accordoServizioParteComune = this.findIdAccordoServizioParteComune(jdbcProperties, log, connection, sqlQueryObject, id, false);
  127.         return id_accordoServizioParteComune != null && id_accordoServizioParteComune > 0;
  128.        
  129.     }
  130.    
  131.     @Override
  132.     public List<IdAccordoServizioParteComune> findAllIds(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCPaginatedExpression expression, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotImplementedException, ServiceException,Exception {

  133.         List<IdAccordoServizioParteComune> list = new ArrayList<IdAccordoServizioParteComune>();

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

  140.         List<Long> ids = this.findAllTableIds(jdbcProperties, log, connection, sqlQueryObject, expression);
  141.        
  142.         for(Long id: ids) {
  143.             AccordoServizioParteComune accordoServizioParteComune = this.get(jdbcProperties, log, connection, sqlQueryObject, id, idMappingResolutionBehaviour);
  144.             IdAccordoServizioParteComune idAccordoServizioParteComune = this.convertToId(jdbcProperties,log,connection,sqlQueryObject,accordoServizioParteComune);
  145.             list.add(idAccordoServizioParteComune);
  146.         }

  147.         return list;
  148.        
  149.     }
  150.    
  151.     @Override
  152.     public List<AccordoServizioParteComune> findAll(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCPaginatedExpression expression, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotImplementedException, ServiceException,Exception {

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

  160.         List<Long> ids = this.findAllTableIds(jdbcProperties, log, connection, sqlQueryObject, expression);
  161.        
  162.         for(Long id: ids) {
  163.             list.add(this.get(jdbcProperties, log, connection, sqlQueryObject, id, idMappingResolutionBehaviour));
  164.         }

  165.         return list;      
  166.        
  167.     }
  168.    
  169.     @Override
  170.     public AccordoServizioParteComune find(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCExpression expression, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour)
  171.         throws NotFoundException, MultipleResultException, NotImplementedException, ServiceException,Exception {

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

  194.     @Override
  195.     public InUse inUse(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdAccordoServizioParteComune id) throws NotFoundException, NotImplementedException, ServiceException,Exception {
  196.        
  197.         Long id_accordoServizioParteComune = this.findIdAccordoServizioParteComune(jdbcProperties, log, connection, sqlQueryObject, id, true);
  198.         return this.inUseEngine(jdbcProperties, log, connection, sqlQueryObject, id_accordoServizioParteComune);
  199.        
  200.     }

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

  233.             return selectEngine(jdbcProperties, log, connection, sqlQueryObject, paginatedExpression, sqlQueryObjectDistinct);
  234.            
  235.         }finally{
  236.             org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.removeFields(sqlQueryObject,paginatedExpression,field);
  237.         }
  238.     }

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

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

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



  375.     // -- ConstructorExpression

  376.     @Override
  377.     public JDBCExpression newExpression(Logger log) throws NotImplementedException, ServiceException {
  378.         try{
  379.             return new JDBCExpression(this.getAccordoServizioParteComuneFieldConverter());
  380.         }catch(Exception e){
  381.             throw new ServiceException(e);
  382.         }
  383.     }


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

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

  413.     @Override
  414.     public void mappingTableIds(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdAccordoServizioParteComune id, AccordoServizioParteComune obj) throws NotFoundException,NotImplementedException,ServiceException,Exception{
  415.         _mappingTableIds(jdbcProperties,log,connection,sqlQueryObject,obj,
  416.                 this.get(jdbcProperties,log,connection,sqlQueryObject,id,null));
  417.     }
  418.    
  419.     @Override
  420.     public void mappingTableIds(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId, AccordoServizioParteComune obj) throws NotFoundException,NotImplementedException,ServiceException,Exception{
  421.         _mappingTableIds(jdbcProperties,log,connection,sqlQueryObject,obj,
  422.                 this.get(jdbcProperties,log,connection,sqlQueryObject,tableId,null));
  423.     }
  424.     private void _mappingTableIds(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, AccordoServizioParteComune obj, AccordoServizioParteComune imgSaved) throws NotFoundException,NotImplementedException,ServiceException,Exception{
  425.         if(imgSaved==null){
  426.             return;
  427.         }
  428.         obj.setId(imgSaved.getId());
  429.         if(obj.getIdReferente()!=null &&
  430.                 imgSaved.getIdReferente()!=null){
  431.             obj.getIdReferente().setId(imgSaved.getIdReferente().getId());
  432.         }
  433.         if(obj.getAccordoServizioParteComuneAzioneList()!=null){
  434.             List<org.openspcoop2.core.commons.search.AccordoServizioParteComuneAzione> listObj_ = obj.getAccordoServizioParteComuneAzioneList();
  435.             for(org.openspcoop2.core.commons.search.AccordoServizioParteComuneAzione itemObj_ : listObj_){
  436.                 org.openspcoop2.core.commons.search.AccordoServizioParteComuneAzione itemAlreadySaved_ = null;
  437.                 if(imgSaved.getAccordoServizioParteComuneAzioneList()!=null){
  438.                     List<org.openspcoop2.core.commons.search.AccordoServizioParteComuneAzione> listImgSaved_ = imgSaved.getAccordoServizioParteComuneAzioneList();
  439.                     for(org.openspcoop2.core.commons.search.AccordoServizioParteComuneAzione itemImgSaved_ : listImgSaved_){
  440.                         boolean objEqualsToImgSaved_ = false;
  441.                         objEqualsToImgSaved_ = org.openspcoop2.generic_project.utils.Utilities.equals(itemObj_.getNome(),itemImgSaved_.getNome());
  442.                         if(objEqualsToImgSaved_){
  443.                             itemAlreadySaved_=itemImgSaved_;
  444.                             break;
  445.                         }
  446.                     }
  447.                 }
  448.                 if(itemAlreadySaved_!=null){
  449.                     itemObj_.setId(itemAlreadySaved_.getId());
  450.                     if(itemObj_.getIdAccordoServizioParteComune()!=null &&
  451.                             itemAlreadySaved_.getIdAccordoServizioParteComune()!=null){
  452.                         itemObj_.getIdAccordoServizioParteComune().setId(itemAlreadySaved_.getIdAccordoServizioParteComune().getId());
  453.                         if(itemObj_.getIdAccordoServizioParteComune().getIdSoggetto()!=null &&
  454.                                 itemAlreadySaved_.getIdAccordoServizioParteComune().getIdSoggetto()!=null){
  455.                             itemObj_.getIdAccordoServizioParteComune().getIdSoggetto().setId(itemAlreadySaved_.getIdAccordoServizioParteComune().getIdSoggetto().getId());
  456.                         }
  457.                     }
  458.                 }
  459.             }
  460.         }
  461.         if(obj.getPortTypeList()!=null){
  462.             List<org.openspcoop2.core.commons.search.PortType> listObj_ = obj.getPortTypeList();
  463.             for(org.openspcoop2.core.commons.search.PortType itemObj_ : listObj_){
  464.                 org.openspcoop2.core.commons.search.PortType itemAlreadySaved_ = null;
  465.                 if(imgSaved.getPortTypeList()!=null){
  466.                     List<org.openspcoop2.core.commons.search.PortType> listImgSaved_ = imgSaved.getPortTypeList();
  467.                     for(org.openspcoop2.core.commons.search.PortType itemImgSaved_ : listImgSaved_){
  468.                         boolean objEqualsToImgSaved_ = false;
  469.                         objEqualsToImgSaved_ = org.openspcoop2.generic_project.utils.Utilities.equals(itemObj_.getNome(),itemImgSaved_.getNome());
  470.                         if(objEqualsToImgSaved_){
  471.                             itemAlreadySaved_=itemImgSaved_;
  472.                             break;
  473.                         }
  474.                     }
  475.                 }
  476.                 if(itemAlreadySaved_!=null){
  477.                     itemObj_.setId(itemAlreadySaved_.getId());
  478.                     if(itemObj_.getOperationList()!=null){
  479.                         List<org.openspcoop2.core.commons.search.Operation> listObj_portType = itemObj_.getOperationList();
  480.                         for(org.openspcoop2.core.commons.search.Operation itemObj_portType : listObj_portType){
  481.                             org.openspcoop2.core.commons.search.Operation itemAlreadySaved_portType = null;
  482.                             if(itemAlreadySaved_.getOperationList()!=null){
  483.                                 List<org.openspcoop2.core.commons.search.Operation> listImgSaved_portType = itemAlreadySaved_.getOperationList();
  484.                                 for(org.openspcoop2.core.commons.search.Operation itemImgSaved_portType : listImgSaved_portType){
  485.                                     boolean objEqualsToImgSaved_portType = false;
  486.                                     objEqualsToImgSaved_portType = org.openspcoop2.generic_project.utils.Utilities.equals(itemObj_portType.getNome(),itemImgSaved_portType.getNome());
  487.                                     if(objEqualsToImgSaved_portType){
  488.                                         itemAlreadySaved_portType=itemImgSaved_portType;
  489.                                         break;
  490.                                     }
  491.                                 }
  492.                             }
  493.                             if(itemAlreadySaved_portType!=null){
  494.                                 itemObj_portType.setId(itemAlreadySaved_portType.getId());
  495.                                 if(itemObj_portType.getIdPortType()!=null &&
  496.                                         itemAlreadySaved_portType.getIdPortType()!=null){
  497.                                     itemObj_portType.getIdPortType().setId(itemAlreadySaved_portType.getIdPortType().getId());
  498.                                     if(itemObj_portType.getIdPortType().getIdAccordoServizioParteComune()!=null &&
  499.                                             itemAlreadySaved_portType.getIdPortType().getIdAccordoServizioParteComune()!=null){
  500.                                         itemObj_portType.getIdPortType().getIdAccordoServizioParteComune().setId(itemAlreadySaved_portType.getIdPortType().getIdAccordoServizioParteComune().getId());
  501.                                         if(itemObj_portType.getIdPortType().getIdAccordoServizioParteComune().getIdSoggetto()!=null &&
  502.                                                 itemAlreadySaved_portType.getIdPortType().getIdAccordoServizioParteComune().getIdSoggetto()!=null){
  503.                                             itemObj_portType.getIdPortType().getIdAccordoServizioParteComune().getIdSoggetto().setId(itemAlreadySaved_portType.getIdPortType().getIdAccordoServizioParteComune().getIdSoggetto().getId());
  504.                                         }
  505.                                     }
  506.                                 }
  507.                             }
  508.                         }
  509.                     }
  510.                     if(itemObj_.getIdAccordoServizioParteComune()!=null &&
  511.                             itemAlreadySaved_.getIdAccordoServizioParteComune()!=null){
  512.                         itemObj_.getIdAccordoServizioParteComune().setId(itemAlreadySaved_.getIdAccordoServizioParteComune().getId());
  513.                         if(itemObj_.getIdAccordoServizioParteComune().getIdSoggetto()!=null &&
  514.                                 itemAlreadySaved_.getIdAccordoServizioParteComune().getIdSoggetto()!=null){
  515.                             itemObj_.getIdAccordoServizioParteComune().getIdSoggetto().setId(itemAlreadySaved_.getIdAccordoServizioParteComune().getIdSoggetto().getId());
  516.                         }
  517.                     }
  518.                 }
  519.             }
  520.         }
  521.         if(obj.getResourceList()!=null){
  522.             List<org.openspcoop2.core.commons.search.Resource> listObj_ = obj.getResourceList();
  523.             for(org.openspcoop2.core.commons.search.Resource itemObj_ : listObj_){
  524.                 org.openspcoop2.core.commons.search.Resource itemAlreadySaved_ = null;
  525.                 if(imgSaved.getResourceList()!=null){
  526.                     List<org.openspcoop2.core.commons.search.Resource> listImgSaved_ = imgSaved.getResourceList();
  527.                     for(org.openspcoop2.core.commons.search.Resource itemImgSaved_ : listImgSaved_){
  528.                         boolean objEqualsToImgSaved_ = false;
  529.                         objEqualsToImgSaved_ = org.openspcoop2.generic_project.utils.Utilities.equals(itemObj_.getNome(),itemImgSaved_.getNome());
  530.                         if(objEqualsToImgSaved_){
  531.                             itemAlreadySaved_=itemImgSaved_;
  532.                             break;
  533.                         }
  534.                     }
  535.                 }
  536.                 if(itemAlreadySaved_!=null){
  537.                     itemObj_.setId(itemAlreadySaved_.getId());
  538.                     if(itemObj_.getIdAccordoServizioParteComune()!=null &&
  539.                             itemAlreadySaved_.getIdAccordoServizioParteComune()!=null){
  540.                         itemObj_.getIdAccordoServizioParteComune().setId(itemAlreadySaved_.getIdAccordoServizioParteComune().getId());
  541.                         if(itemObj_.getIdAccordoServizioParteComune().getIdSoggetto()!=null &&
  542.                                 itemAlreadySaved_.getIdAccordoServizioParteComune().getIdSoggetto()!=null){
  543.                             itemObj_.getIdAccordoServizioParteComune().getIdSoggetto().setId(itemAlreadySaved_.getIdAccordoServizioParteComune().getIdSoggetto().getId());
  544.                         }
  545.                     }
  546.                 }
  547.             }
  548.         }
  549.         if(obj.getAccordoServizioParteComuneGruppoList()!=null){
  550.             List<org.openspcoop2.core.commons.search.AccordoServizioParteComuneGruppo> listObj_ = obj.getAccordoServizioParteComuneGruppoList();
  551.             for(org.openspcoop2.core.commons.search.AccordoServizioParteComuneGruppo itemObj_ : listObj_){
  552.                 org.openspcoop2.core.commons.search.AccordoServizioParteComuneGruppo itemAlreadySaved_ = null;
  553.                 if(imgSaved.getAccordoServizioParteComuneGruppoList()!=null){
  554.                     List<org.openspcoop2.core.commons.search.AccordoServizioParteComuneGruppo> listImgSaved_ = imgSaved.getAccordoServizioParteComuneGruppoList();
  555.                     for(org.openspcoop2.core.commons.search.AccordoServizioParteComuneGruppo itemImgSaved_ : listImgSaved_){
  556.                         boolean objEqualsToImgSaved_ = false;
  557.                         objEqualsToImgSaved_ = org.openspcoop2.generic_project.utils.Utilities.equals(itemObj_.getIdGruppo().getNome(),itemImgSaved_.getIdGruppo().getNome()) &&
  558.                                                  org.openspcoop2.generic_project.utils.Utilities.equals(itemObj_.getIdAccordoServizioParteComune().getNome(),itemImgSaved_.getIdAccordoServizioParteComune().getNome())  &&
  559.                                                  org.openspcoop2.generic_project.utils.Utilities.equals(itemObj_.getIdAccordoServizioParteComune().getIdSoggetto().getTipo(),itemImgSaved_.getIdAccordoServizioParteComune().getIdSoggetto().getTipo())  &&
  560.                                                  org.openspcoop2.generic_project.utils.Utilities.equals(itemObj_.getIdAccordoServizioParteComune().getIdSoggetto().getNome(),itemImgSaved_.getIdAccordoServizioParteComune().getIdSoggetto().getNome())  &&
  561.                                                  org.openspcoop2.generic_project.utils.Utilities.equals(itemObj_.getIdAccordoServizioParteComune().getVersione(),itemImgSaved_.getIdAccordoServizioParteComune().getVersione());
  562.                         if(objEqualsToImgSaved_){
  563.                             itemAlreadySaved_=itemImgSaved_;
  564.                             break;
  565.                         }
  566.                     }
  567.                 }
  568.                 if(itemAlreadySaved_!=null){
  569.                     itemObj_.setId(itemAlreadySaved_.getId());
  570.                     if(itemObj_.getIdGruppo()!=null &&
  571.                             itemAlreadySaved_.getIdGruppo()!=null){
  572.                         itemObj_.getIdGruppo().setId(itemAlreadySaved_.getIdGruppo().getId());
  573.                     }
  574.                     if(itemObj_.getIdAccordoServizioParteComune()!=null &&
  575.                             itemAlreadySaved_.getIdAccordoServizioParteComune()!=null){
  576.                         itemObj_.getIdAccordoServizioParteComune().setId(itemAlreadySaved_.getIdAccordoServizioParteComune().getId());
  577.                         if(itemObj_.getIdAccordoServizioParteComune().getIdSoggetto()!=null &&
  578.                                 itemAlreadySaved_.getIdAccordoServizioParteComune().getIdSoggetto()!=null){
  579.                             itemObj_.getIdAccordoServizioParteComune().getIdSoggetto().setId(itemAlreadySaved_.getIdAccordoServizioParteComune().getIdSoggetto().getId());
  580.                         }
  581.                     }
  582.                 }
  583.             }
  584.         }
  585.              
  586.     }
  587.    
  588.     @Override
  589.     public AccordoServizioParteComune get(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotFoundException, MultipleResultException, NotImplementedException, ServiceException, Exception {
  590.         return this.getEngine(jdbcProperties, log, connection, sqlQueryObject, Long.valueOf(tableId), idMappingResolutionBehaviour);
  591.     }
  592.    
  593.     private AccordoServizioParteComune getEngine(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, Long tableId, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotFoundException, MultipleResultException, NotImplementedException, ServiceException, Exception {
  594.    
  595.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  596.                     new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);
  597.        
  598.         ISQLQueryObject sqlQueryObjectGet = sqlQueryObject.newSQLQueryObject();
  599.                
  600.         AccordoServizioParteComune accordoServizioParteComune = new AccordoServizioParteComune();
  601.        

  602.         // Object accordoServizioParteComune
  603.         ISQLQueryObject sqlQueryObjectGet_accordoServizioParteComune = sqlQueryObjectGet.newSQLQueryObject();
  604.         sqlQueryObjectGet_accordoServizioParteComune.setANDLogicOperator(true);
  605.         sqlQueryObjectGet_accordoServizioParteComune.addFromTable(this.getAccordoServizioParteComuneFieldConverter().toTable(AccordoServizioParteComune.model()));
  606.         sqlQueryObjectGet_accordoServizioParteComune.addSelectField("id");
  607.         sqlQueryObjectGet_accordoServizioParteComune.addSelectField(this.getAccordoServizioParteComuneFieldConverter().toColumn(AccordoServizioParteComune.model().NOME,true));
  608.         sqlQueryObjectGet_accordoServizioParteComune.addSelectField(this.getAccordoServizioParteComuneFieldConverter().toColumn(AccordoServizioParteComune.model().VERSIONE,true));
  609.         sqlQueryObjectGet_accordoServizioParteComune.addSelectField(this.getAccordoServizioParteComuneFieldConverter().toColumn(AccordoServizioParteComune.model().SERVICE_BINDING,true));
  610.         sqlQueryObjectGet_accordoServizioParteComune.addSelectField(this.getAccordoServizioParteComuneFieldConverter().toColumn(AccordoServizioParteComune.model().CANALE,true));
  611.         sqlQueryObjectGet_accordoServizioParteComune.addWhereCondition("id=?");

  612.         // Get accordoServizioParteComune
  613.         accordoServizioParteComune = (AccordoServizioParteComune) jdbcUtilities.executeQuerySingleResult(sqlQueryObjectGet_accordoServizioParteComune.createSQLQuery(), jdbcProperties.isShowSql(), AccordoServizioParteComune.model(), this.getAccordoServizioParteComuneFetch(),
  614.             new JDBCObject(tableId,Long.class));

  615.        
  616.         // Recupero idSoggetto
  617.         ISQLQueryObject sqlQueryObjectGet_accordoServizioParteComune_soggetto = sqlQueryObjectGet.newSQLQueryObject();
  618.         sqlQueryObjectGet_accordoServizioParteComune_soggetto.addFromTable(this.getAccordoServizioParteComuneFieldConverter().toTable(AccordoServizioParteComune.model()));
  619.         sqlQueryObjectGet_accordoServizioParteComune_soggetto.addSelectField("id_referente");
  620.         sqlQueryObjectGet_accordoServizioParteComune_soggetto.setANDLogicOperator(true);
  621.         sqlQueryObjectGet_accordoServizioParteComune_soggetto.addWhereCondition("id=?");
  622.        
  623.         // Recupero _accordoServizioParteComune_soggetto
  624.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject [] searchParams_accordoServizioParteComune_soggetto = new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject [] {
  625.                 new JDBCObject(accordoServizioParteComune.getId(), Long.class)
  626.         };
  627.         Long id_accordoServizioParteComune_soggetto =
  628.             (Long) jdbcUtilities.executeQuerySingleResult(sqlQueryObjectGet_accordoServizioParteComune_soggetto.createSQLQuery(), jdbcProperties.isShowSql(),
  629.             Long.class, searchParams_accordoServizioParteComune_soggetto);
  630.        
  631.         if(id_accordoServizioParteComune_soggetto!=null && id_accordoServizioParteComune_soggetto>0){
  632.             Soggetto soggetto = ((IDBSoggettoServiceSearch)this.getServiceManager(connection, jdbcProperties, log).getSoggettoServiceSearch()).get(id_accordoServizioParteComune_soggetto);
  633.             IdSoggetto idReferente = new IdSoggetto();
  634.             idReferente.setTipo(soggetto.getTipoSoggetto());
  635.             idReferente.setNome(soggetto.getNomeSoggetto());
  636.             accordoServizioParteComune.setIdReferente(idReferente);
  637.         }


  638.         // Object accordoServizioParteComune_accordoServizioParteComuneAzione
  639.         ISQLQueryObject sqlQueryObjectGet_accordoServizioParteComune_accordoServizioParteComuneAzione = sqlQueryObjectGet.newSQLQueryObject();
  640.         sqlQueryObjectGet_accordoServizioParteComune_accordoServizioParteComuneAzione.setANDLogicOperator(true);
  641.         sqlQueryObjectGet_accordoServizioParteComune_accordoServizioParteComuneAzione.addFromTable(this.getAccordoServizioParteComuneFieldConverter().toTable(AccordoServizioParteComune.model().ACCORDO_SERVIZIO_PARTE_COMUNE_AZIONE));
  642.         sqlQueryObjectGet_accordoServizioParteComune_accordoServizioParteComuneAzione.addSelectField("id");
  643.         sqlQueryObjectGet_accordoServizioParteComune_accordoServizioParteComuneAzione.addSelectField(this.getAccordoServizioParteComuneFieldConverter().toColumn(AccordoServizioParteComune.model().ACCORDO_SERVIZIO_PARTE_COMUNE_AZIONE.NOME,true));
  644.         sqlQueryObjectGet_accordoServizioParteComune_accordoServizioParteComuneAzione.addWhereCondition("id_accordo=?");

  645.         // Get accordoServizioParteComune_accordoServizioParteComuneAzione
  646.         java.util.List<Object> accordoServizioParteComune_accordoServizioParteComuneAzione_list = jdbcUtilities.executeQuery(sqlQueryObjectGet_accordoServizioParteComune_accordoServizioParteComuneAzione.createSQLQuery(), jdbcProperties.isShowSql(), AccordoServizioParteComune.model().ACCORDO_SERVIZIO_PARTE_COMUNE_AZIONE, this.getAccordoServizioParteComuneFetch(),
  647.             new JDBCObject(accordoServizioParteComune.getId(),Long.class));

  648.         if(accordoServizioParteComune_accordoServizioParteComuneAzione_list != null) {
  649.             for (Object accordoServizioParteComune_accordoServizioParteComuneAzione_object: accordoServizioParteComune_accordoServizioParteComuneAzione_list) {
  650.                 AccordoServizioParteComuneAzione accordoServizioParteComune_accordoServizioParteComuneAzione = (AccordoServizioParteComuneAzione) accordoServizioParteComune_accordoServizioParteComuneAzione_object;


  651.                 accordoServizioParteComune.addAccordoServizioParteComuneAzione(accordoServizioParteComune_accordoServizioParteComuneAzione);
  652.             }
  653.         }

  654.         // Object accordoServizioParteComune_portType
  655.         ISQLQueryObject sqlQueryObjectGet_accordoServizioParteComune_portType = sqlQueryObjectGet.newSQLQueryObject();
  656.         sqlQueryObjectGet_accordoServizioParteComune_portType.setANDLogicOperator(true);
  657.         sqlQueryObjectGet_accordoServizioParteComune_portType.addFromTable(this.getAccordoServizioParteComuneFieldConverter().toTable(AccordoServizioParteComune.model().PORT_TYPE));
  658.         sqlQueryObjectGet_accordoServizioParteComune_portType.addSelectField("id");
  659.         sqlQueryObjectGet_accordoServizioParteComune_portType.addSelectField(this.getAccordoServizioParteComuneFieldConverter().toColumn(AccordoServizioParteComune.model().PORT_TYPE.NOME,true));
  660.         sqlQueryObjectGet_accordoServizioParteComune_portType.addWhereCondition("id_accordo=?");

  661.         // Get accordoServizioParteComune_portType
  662.         java.util.List<Object> accordoServizioParteComune_portType_list = jdbcUtilities.executeQuery(sqlQueryObjectGet_accordoServizioParteComune_portType.createSQLQuery(), jdbcProperties.isShowSql(), AccordoServizioParteComune.model().PORT_TYPE, this.getAccordoServizioParteComuneFetch(),
  663.             new JDBCObject(accordoServizioParteComune.getId(),Long.class));

  664.         if(accordoServizioParteComune_portType_list != null) {
  665.             for (Object accordoServizioParteComune_portType_object: accordoServizioParteComune_portType_list) {
  666.                 PortType accordoServizioParteComune_portType = (PortType) accordoServizioParteComune_portType_object;



  667.                 // Object accordoServizioParteComune_portType_operation
  668.                 ISQLQueryObject sqlQueryObjectGet_accordoServizioParteComune_portType_operation = sqlQueryObjectGet.newSQLQueryObject();
  669.                 sqlQueryObjectGet_accordoServizioParteComune_portType_operation.setANDLogicOperator(true);
  670.                 sqlQueryObjectGet_accordoServizioParteComune_portType_operation.addFromTable(this.getAccordoServizioParteComuneFieldConverter().toTable(AccordoServizioParteComune.model().PORT_TYPE.OPERATION));
  671.                 sqlQueryObjectGet_accordoServizioParteComune_portType_operation.addSelectField("id");
  672.                 sqlQueryObjectGet_accordoServizioParteComune_portType_operation.addSelectField(this.getAccordoServizioParteComuneFieldConverter().toColumn(AccordoServizioParteComune.model().PORT_TYPE.OPERATION.NOME,true));
  673.                 sqlQueryObjectGet_accordoServizioParteComune_portType_operation.addWhereCondition("id_port_type=?");

  674.                 // Get accordoServizioParteComune_portType_operation
  675.                 java.util.List<Object> accordoServizioParteComune_portType_operation_list = jdbcUtilities.executeQuery(sqlQueryObjectGet_accordoServizioParteComune_portType_operation.createSQLQuery(), jdbcProperties.isShowSql(), AccordoServizioParteComune.model().PORT_TYPE.OPERATION, this.getAccordoServizioParteComuneFetch(),
  676.                     new JDBCObject(accordoServizioParteComune_portType.getId(),Long.class));

  677.                 if(accordoServizioParteComune_portType_operation_list != null) {
  678.                     for (Object accordoServizioParteComune_portType_operation_object: accordoServizioParteComune_portType_operation_list) {
  679.                         Operation accordoServizioParteComune_portType_operation = (Operation) accordoServizioParteComune_portType_operation_object;


  680.                         accordoServizioParteComune_portType.addOperation(accordoServizioParteComune_portType_operation);
  681.                     }
  682.                 }
  683.                 accordoServizioParteComune.addPortType(accordoServizioParteComune_portType);
  684.             }
  685.         }

  686.         // Object accordoServizioParteComune_resource
  687.         ISQLQueryObject sqlQueryObjectGet_accordoServizioParteComune_resource = sqlQueryObjectGet.newSQLQueryObject();
  688.         sqlQueryObjectGet_accordoServizioParteComune_resource.setANDLogicOperator(true);
  689.         sqlQueryObjectGet_accordoServizioParteComune_resource.addFromTable(this.getAccordoServizioParteComuneFieldConverter().toTable(AccordoServizioParteComune.model().RESOURCE));
  690.         sqlQueryObjectGet_accordoServizioParteComune_resource.addSelectField("id");
  691.         sqlQueryObjectGet_accordoServizioParteComune_resource.addSelectField(this.getAccordoServizioParteComuneFieldConverter().toColumn(AccordoServizioParteComune.model().RESOURCE.NOME,true));
  692.         sqlQueryObjectGet_accordoServizioParteComune_resource.addSelectField(this.getAccordoServizioParteComuneFieldConverter().toColumn(AccordoServizioParteComune.model().RESOURCE.HTTP_METHOD,true));
  693.         sqlQueryObjectGet_accordoServizioParteComune_resource.addSelectField(this.getAccordoServizioParteComuneFieldConverter().toColumn(AccordoServizioParteComune.model().RESOURCE.PATH,true));
  694.         sqlQueryObjectGet_accordoServizioParteComune_resource.addWhereCondition("id_accordo=?");

  695.         // Get accordoServizioParteComune_resource
  696.         java.util.List<Object> accordoServizioParteComune_resource_list = jdbcUtilities.executeQuery(sqlQueryObjectGet_accordoServizioParteComune_resource.createSQLQuery(), jdbcProperties.isShowSql(), AccordoServizioParteComune.model().RESOURCE, this.getAccordoServizioParteComuneFetch(),
  697.             new JDBCObject(accordoServizioParteComune.getId(),Long.class));

  698.         if(accordoServizioParteComune_resource_list != null) {
  699.             for (Object accordoServizioParteComune_resource_object: accordoServizioParteComune_resource_list) {
  700.                 Resource accordoServizioParteComune_resource = (Resource) accordoServizioParteComune_resource_object;


  701.                 accordoServizioParteComune.addResource(accordoServizioParteComune_resource);
  702.             }
  703.         }

  704.         // Object accordoServizioParteComune_accordoServizioParteComuneGruppo
  705.         ISQLQueryObject sqlQueryObjectGet_accordoServizioParteComune_accordoServizioParteComuneGruppo = sqlQueryObjectGet.newSQLQueryObject();
  706.         sqlQueryObjectGet_accordoServizioParteComune_accordoServizioParteComuneGruppo.setANDLogicOperator(true);
  707.         sqlQueryObjectGet_accordoServizioParteComune_accordoServizioParteComuneGruppo.addFromTable(this.getAccordoServizioParteComuneFieldConverter().toTable(AccordoServizioParteComune.model().ACCORDO_SERVIZIO_PARTE_COMUNE_GRUPPO));
  708.         sqlQueryObjectGet_accordoServizioParteComune_accordoServizioParteComuneGruppo.addSelectField("id");
  709.         sqlQueryObjectGet_accordoServizioParteComune_accordoServizioParteComuneGruppo.addWhereCondition("id_accordo=?");

  710.         // Get accordoServizioParteComune_accordoServizioParteComuneGruppo
  711.         java.util.List<Object> accordoServizioParteComune_accordoServizioParteComuneGruppo_list = (java.util.List<Object>) jdbcUtilities.executeQuery(sqlQueryObjectGet_accordoServizioParteComune_accordoServizioParteComuneGruppo.createSQLQuery(), jdbcProperties.isShowSql(), AccordoServizioParteComune.model().ACCORDO_SERVIZIO_PARTE_COMUNE_GRUPPO, this.getAccordoServizioParteComuneFetch(),
  712.             new JDBCObject(accordoServizioParteComune.getId(),Long.class));

  713.         if(accordoServizioParteComune_accordoServizioParteComuneGruppo_list != null) {
  714.             for (Object accordoServizioParteComune_accordoServizioParteComuneGruppo_object: accordoServizioParteComune_accordoServizioParteComuneGruppo_list) {
  715.                 AccordoServizioParteComuneGruppo accordoServizioParteComune_accordoServizioParteComuneGruppo = (AccordoServizioParteComuneGruppo) accordoServizioParteComune_accordoServizioParteComuneGruppo_object;


  716.                 if(idMappingResolutionBehaviour==null ||
  717.                     (org.openspcoop2.generic_project.beans.IDMappingBehaviour.ENABLED.equals(idMappingResolutionBehaviour) || org.openspcoop2.generic_project.beans.IDMappingBehaviour.USE_TABLE_ID.equals(idMappingResolutionBehaviour))
  718.                 ){
  719.                     // Object _accordoServizioParteComune_accordoServizioParteComuneGruppo_gruppo (recupero id)
  720.                     ISQLQueryObject sqlQueryObjectGet_accordoServizioParteComune_accordoServizioParteComuneGruppo_gruppo_readFkId = sqlQueryObjectGet.newSQLQueryObject();
  721.                     sqlQueryObjectGet_accordoServizioParteComune_accordoServizioParteComuneGruppo_gruppo_readFkId.addFromTable(this.getAccordoServizioParteComuneFieldConverter().toTable(org.openspcoop2.core.commons.search.AccordoServizioParteComune.model().ACCORDO_SERVIZIO_PARTE_COMUNE_GRUPPO));
  722.                     sqlQueryObjectGet_accordoServizioParteComune_accordoServizioParteComuneGruppo_gruppo_readFkId.addSelectField("id_gruppo");
  723.                     sqlQueryObjectGet_accordoServizioParteComune_accordoServizioParteComuneGruppo_gruppo_readFkId.addWhereCondition("id=?");
  724.                     sqlQueryObjectGet_accordoServizioParteComune_accordoServizioParteComuneGruppo_gruppo_readFkId.setANDLogicOperator(true);
  725.                     Long idFK_accordoServizioParteComune_accordoServizioParteComuneGruppo_gruppo = (Long) jdbcUtilities.executeQuerySingleResult(sqlQueryObjectGet_accordoServizioParteComune_accordoServizioParteComuneGruppo_gruppo_readFkId.createSQLQuery(), jdbcProperties.isShowSql(),Long.class,
  726.                             new JDBCObject(accordoServizioParteComune_accordoServizioParteComuneGruppo.getId(),Long.class));
  727.                    
  728.                     org.openspcoop2.core.commons.search.IdGruppo id_accordoServizioParteComune_accordoServizioParteComuneGruppo_gruppo = null;
  729.                     if(idMappingResolutionBehaviour==null || org.openspcoop2.generic_project.beans.IDMappingBehaviour.ENABLED.equals(idMappingResolutionBehaviour)){
  730.                         id_accordoServizioParteComune_accordoServizioParteComuneGruppo_gruppo = ((JDBCGruppoServiceSearch)(this.getServiceManager(connection, jdbcProperties, log).getGruppoServiceSearch())).findId(idFK_accordoServizioParteComune_accordoServizioParteComuneGruppo_gruppo, false);
  731.                     }else{
  732.                         id_accordoServizioParteComune_accordoServizioParteComuneGruppo_gruppo = new org.openspcoop2.core.commons.search.IdGruppo();
  733.                     }
  734.                     id_accordoServizioParteComune_accordoServizioParteComuneGruppo_gruppo.setId(idFK_accordoServizioParteComune_accordoServizioParteComuneGruppo_gruppo);
  735.                     accordoServizioParteComune_accordoServizioParteComuneGruppo.setIdGruppo(id_accordoServizioParteComune_accordoServizioParteComuneGruppo_gruppo);
  736.                 }

  737.                 /*
  738.                 if(idMappingResolutionBehaviour==null ||
  739.                     (org.openspcoop2.generic_project.beans.IDMappingBehaviour.ENABLED.equals(idMappingResolutionBehaviour) || org.openspcoop2.generic_project.beans.IDMappingBehaviour.USE_TABLE_ID.equals(idMappingResolutionBehaviour))
  740.                 ){
  741.                     // Object _accordoServizioParteComune_accordoServizioParteComuneGruppo_accordoServizioParteComune (recupero id)
  742.                     ISQLQueryObject sqlQueryObjectGet_accordoServizioParteComune_accordoServizioParteComuneGruppo_accordoServizioParteComune_readFkId = sqlQueryObjectGet.newSQLQueryObject();
  743.                     sqlQueryObjectGet_accordoServizioParteComune_accordoServizioParteComuneGruppo_accordoServizioParteComune_readFkId.addFromTable(this.getAccordoServizioParteComuneFieldConverter().toTable(org.openspcoop2.core.commons.search.AccordoServizioParteComune.model().ACCORDO_SERVIZIO_PARTE_COMUNE_GRUPPO));
  744.                     sqlQueryObjectGet_accordoServizioParteComune_accordoServizioParteComuneGruppo_accordoServizioParteComune_readFkId.addSelectField("id_accordo");
  745.                     sqlQueryObjectGet_accordoServizioParteComune_accordoServizioParteComuneGruppo_accordoServizioParteComune_readFkId.addWhereCondition("id=?");
  746.                     sqlQueryObjectGet_accordoServizioParteComune_accordoServizioParteComuneGruppo_accordoServizioParteComune_readFkId.setANDLogicOperator(true);
  747.                     Long idFK_accordoServizioParteComune_accordoServizioParteComuneGruppo_accordoServizioParteComune = (Long) jdbcUtilities.executeQuerySingleResult(sqlQueryObjectGet_accordoServizioParteComune_accordoServizioParteComuneGruppo_accordoServizioParteComune_readFkId.createSQLQuery(), jdbcProperties.isShowSql(),Long.class,
  748.                             new JDBCObject(accordoServizioParteComune_accordoServizioParteComuneGruppo.getId(),Long.class));
  749.                    
  750.                     org.openspcoop2.core.commons.search.IdAccordoServizioParteComune id_accordoServizioParteComune_accordoServizioParteComuneGruppo_accordoServizioParteComune = null;
  751.                     if(idMappingResolutionBehaviour==null || org.openspcoop2.generic_project.beans.IDMappingBehaviour.ENABLED.equals(idMappingResolutionBehaviour)){
  752.                         id_accordoServizioParteComune_accordoServizioParteComuneGruppo_accordoServizioParteComune = ((JDBCAccordoServizioParteComuneServiceSearch)(this.getServiceManager(connection, jdbcProperties, log).getAccordoServizioParteComuneServiceSearch())).findId(idFK_accordoServizioParteComune_accordoServizioParteComuneGruppo_accordoServizioParteComune, false);
  753.                     }else{
  754.                         id_accordoServizioParteComune_accordoServizioParteComuneGruppo_accordoServizioParteComune = new org.openspcoop2.core.commons.search.IdAccordoServizioParteComune();
  755.                     }
  756.                     id_accordoServizioParteComune_accordoServizioParteComuneGruppo_accordoServizioParteComune.setId(idFK_accordoServizioParteComune_accordoServizioParteComuneGruppo_accordoServizioParteComune);
  757.                     accordoServizioParteComune_accordoServizioParteComuneGruppo.setIdAccordoServizioParteComune(id_accordoServizioParteComune_accordoServizioParteComuneGruppo_accordoServizioParteComune);
  758.                 }*/
  759.                 //  me stesso
  760.                 org.openspcoop2.core.commons.search.IdAccordoServizioParteComune id_accordoServizioParteComune_accordoServizioParteComuneGruppo_accordoServizioParteComune = new org.openspcoop2.core.commons.search.IdAccordoServizioParteComune();
  761.                 id_accordoServizioParteComune_accordoServizioParteComuneGruppo_accordoServizioParteComune.setId(accordoServizioParteComune.getId());
  762.                 id_accordoServizioParteComune_accordoServizioParteComuneGruppo_accordoServizioParteComune.setNome(accordoServizioParteComune.getNome());
  763.                 id_accordoServizioParteComune_accordoServizioParteComuneGruppo_accordoServizioParteComune.setIdSoggetto(accordoServizioParteComune.getIdReferente());
  764.                 id_accordoServizioParteComune_accordoServizioParteComuneGruppo_accordoServizioParteComune.setVersione(accordoServizioParteComune.getVersione());
  765.                 accordoServizioParteComune_accordoServizioParteComuneGruppo.setIdAccordoServizioParteComune(id_accordoServizioParteComune_accordoServizioParteComuneGruppo_accordoServizioParteComune);
  766.                    

  767.                 accordoServizioParteComune.addAccordoServizioParteComuneGruppo(accordoServizioParteComune_accordoServizioParteComuneGruppo);
  768.             }
  769.         }              
  770.        
  771.         return accordoServizioParteComune;  
  772.    
  773.     }
  774.    
  775.     @Override
  776.     public boolean exists(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId) throws MultipleResultException, NotImplementedException, ServiceException, Exception {
  777.         return this._exists(jdbcProperties, log, connection, sqlQueryObject, Long.valueOf(tableId));
  778.     }
  779.    
  780.     private boolean _exists(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, Long tableId) throws MultipleResultException, NotImplementedException, ServiceException, Exception {
  781.    
  782.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  783.                     new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);
  784.                
  785.         boolean existsAccordoServizioParteComune = false;

  786.         sqlQueryObject = sqlQueryObject.newSQLQueryObject();
  787.         sqlQueryObject.setANDLogicOperator(true);

  788.         sqlQueryObject.addFromTable(this.getAccordoServizioParteComuneFieldConverter().toTable(AccordoServizioParteComune.model()));
  789.         sqlQueryObject.addSelectField(this.getAccordoServizioParteComuneFieldConverter().toColumn(AccordoServizioParteComune.model().NOME,true));
  790.         sqlQueryObject.addWhereCondition("id=?");


  791.         // Exists accordoServizioParteComune
  792.         existsAccordoServizioParteComune = jdbcUtilities.exists(sqlQueryObject.createSQLQuery(), jdbcProperties.isShowSql(),
  793.             new JDBCObject(tableId,Long.class));

  794.        
  795.         return existsAccordoServizioParteComune;
  796.    
  797.     }
  798.    
  799.     private void joinEngine(IExpression expression, ISQLQueryObject sqlQueryObject) throws NotImplementedException, ServiceException, Exception{
  800.    
  801.         boolean addReferente = false;
  802.         if(expression.inUseModel(AccordoServizioParteComune.model().ID_REFERENTE,false)){
  803.             String tableName1 = this.getAccordoServizioParteComuneFieldConverter().toTable(AccordoServizioParteComune.model());
  804.             String tableName2 = this.getAccordoServizioParteComuneFieldConverter().toTable(AccordoServizioParteComune.model().ID_REFERENTE);
  805.             sqlQueryObject.addWhereCondition(tableName1+".id_referente="+tableName2+".id");
  806.             addReferente = true;
  807.         }
  808.         if(expression.inUseModel(AccordoServizioParteComune.model().PORT_TYPE.OPERATION.ID_PORT_TYPE.ID_ACCORDO_SERVIZIO_PARTE_COMUNE.ID_SOGGETTO,false) &&
  809.                 !addReferente){
  810.             String tableName1 = this.getAccordoServizioParteComuneFieldConverter().toTable(AccordoServizioParteComune.model());
  811.             String tableName2 = this.getAccordoServizioParteComuneFieldConverter().toTable(AccordoServizioParteComune.model().PORT_TYPE.OPERATION.ID_PORT_TYPE.ID_ACCORDO_SERVIZIO_PARTE_COMUNE.ID_SOGGETTO);
  812.             sqlQueryObject.addWhereCondition(tableName1+".id_referente="+tableName2+".id");
  813.             addReferente = true;
  814.         }
  815.         if(expression.inUseModel(AccordoServizioParteComune.model().PORT_TYPE.ID_ACCORDO_SERVIZIO_PARTE_COMUNE.ID_SOGGETTO,false) &&
  816.                 !addReferente){
  817.             String tableName1 = this.getAccordoServizioParteComuneFieldConverter().toTable(AccordoServizioParteComune.model());
  818.             String tableName2 = this.getAccordoServizioParteComuneFieldConverter().toTable(AccordoServizioParteComune.model().PORT_TYPE.ID_ACCORDO_SERVIZIO_PARTE_COMUNE.ID_SOGGETTO);
  819.             sqlQueryObject.addWhereCondition(tableName1+".id_referente="+tableName2+".id");
  820.             addReferente = true;
  821.         }
  822.         if(expression.inUseModel(AccordoServizioParteComune.model().ACCORDO_SERVIZIO_PARTE_COMUNE_AZIONE.ID_ACCORDO_SERVIZIO_PARTE_COMUNE.ID_SOGGETTO,false) &&
  823.                 !addReferente){
  824.             String tableName1 = this.getAccordoServizioParteComuneFieldConverter().toTable(AccordoServizioParteComune.model());
  825.             String tableName2 = this.getAccordoServizioParteComuneFieldConverter().toTable(AccordoServizioParteComune.model().ACCORDO_SERVIZIO_PARTE_COMUNE_AZIONE.ID_ACCORDO_SERVIZIO_PARTE_COMUNE.ID_SOGGETTO);
  826.             sqlQueryObject.addWhereCondition(tableName1+".id_referente="+tableName2+".id");
  827.             addReferente = true;
  828.         }
  829.         if(expression.inUseModel(AccordoServizioParteComune.model().RESOURCE.ID_ACCORDO_SERVIZIO_PARTE_COMUNE.ID_SOGGETTO,false) &&
  830.                 !addReferente){
  831.             String tableName1 = this.getAccordoServizioParteComuneFieldConverter().toTable(AccordoServizioParteComune.model());
  832.             String tableName2 = this.getAccordoServizioParteComuneFieldConverter().toTable(AccordoServizioParteComune.model().RESOURCE.ID_ACCORDO_SERVIZIO_PARTE_COMUNE.ID_SOGGETTO);
  833.             sqlQueryObject.addWhereCondition(tableName1+".id_referente="+tableName2+".id");
  834.             addReferente = true;
  835.         }
  836.         if(expression.inUseModel(AccordoServizioParteComune.model().ACCORDO_SERVIZIO_PARTE_COMUNE_GRUPPO.ID_ACCORDO_SERVIZIO_PARTE_COMUNE.ID_SOGGETTO,false) &&
  837.                 !addReferente){
  838.             String tableName1 = this.getAccordoServizioParteComuneFieldConverter().toTable(AccordoServizioParteComune.model());
  839.             String tableName2 = this.getAccordoServizioParteComuneFieldConverter().toTable(AccordoServizioParteComune.model().ACCORDO_SERVIZIO_PARTE_COMUNE_GRUPPO.ID_ACCORDO_SERVIZIO_PARTE_COMUNE.ID_SOGGETTO);
  840.             sqlQueryObject.addWhereCondition(tableName1+".id_referente="+tableName2+".id");
  841.             addReferente = true;
  842.         }
  843.        
  844.        
  845.         if(expression.inUseModel(AccordoServizioParteComune.model().ACCORDO_SERVIZIO_PARTE_COMUNE_AZIONE,false)){
  846.             String tableName1 = this.getAccordoServizioParteComuneFieldConverter().toTable(AccordoServizioParteComune.model().ACCORDO_SERVIZIO_PARTE_COMUNE_AZIONE);
  847.             String tableName2 = this.getAccordoServizioParteComuneFieldConverter().toTable(AccordoServizioParteComune.model());
  848.             sqlQueryObject.addWhereCondition(tableName1+".id_accordo="+tableName2+".id");
  849.         }
  850.        
  851.         if(expression.inUseModel(AccordoServizioParteComune.model().PORT_TYPE,false)){
  852.             String tableName1 = this.getAccordoServizioParteComuneFieldConverter().toTable(AccordoServizioParteComune.model().PORT_TYPE);
  853.             String tableName2 = this.getAccordoServizioParteComuneFieldConverter().toTable(AccordoServizioParteComune.model());
  854.             sqlQueryObject.addWhereCondition(tableName1+".id_accordo="+tableName2+".id");
  855.         }
  856.         if(expression.inUseModel(AccordoServizioParteComune.model().PORT_TYPE.OPERATION.ID_PORT_TYPE,false) &&
  857.                 !expression.inUseModel(AccordoServizioParteComune.model().PORT_TYPE,false)){
  858.             String tableName1 = this.getAccordoServizioParteComuneFieldConverter().toTable(AccordoServizioParteComune.model().PORT_TYPE.OPERATION.ID_PORT_TYPE);
  859.             String tableName2 = this.getAccordoServizioParteComuneFieldConverter().toTable(AccordoServizioParteComune.model());
  860.             sqlQueryObject.addWhereCondition(tableName1+".id_accordo="+tableName2+".id");
  861.         }
  862.        
  863.         if(expression.inUseModel(AccordoServizioParteComune.model().PORT_TYPE.OPERATION,false)){
  864.             String tableName1 = this.getAccordoServizioParteComuneFieldConverter().toTable(AccordoServizioParteComune.model().PORT_TYPE.OPERATION);
  865.             String tableName2 = this.getAccordoServizioParteComuneFieldConverter().toTable(AccordoServizioParteComune.model().PORT_TYPE);
  866.             sqlQueryObject.addWhereCondition(tableName1+".id_port_type="+tableName2+".id");
  867.         }
  868.        
  869.         if(expression.inUseModel(AccordoServizioParteComune.model().RESOURCE,false)){
  870.             String tableName1 = this.getAccordoServizioParteComuneFieldConverter().toTable(AccordoServizioParteComune.model().RESOURCE);
  871.             String tableName2 = this.getAccordoServizioParteComuneFieldConverter().toTable(AccordoServizioParteComune.model());
  872.             sqlQueryObject.addWhereCondition(tableName1+".id_accordo="+tableName2+".id");
  873.         }
  874.        
  875.         boolean addJoinAccordiToAccordiGruppi = false;
  876.         if(expression.inUseModel(AccordoServizioParteComune.model().ACCORDO_SERVIZIO_PARTE_COMUNE_GRUPPO,false)){
  877.             String tableName1 = this.getAccordoServizioParteComuneFieldConverter().toTable(AccordoServizioParteComune.model().ACCORDO_SERVIZIO_PARTE_COMUNE_GRUPPO);
  878.             String tableName2 = this.getAccordoServizioParteComuneFieldConverter().toTable(AccordoServizioParteComune.model());
  879.             sqlQueryObject.addWhereCondition(tableName1+".id_accordo="+tableName2+".id");
  880.             addJoinAccordiToAccordiGruppi = true;
  881.         }
  882.         if(expression.inUseModel(AccordoServizioParteComune.model().ACCORDO_SERVIZIO_PARTE_COMUNE_GRUPPO.ID_GRUPPO,false)){
  883.             String tableName1 = this.getAccordoServizioParteComuneFieldConverter().toTable(AccordoServizioParteComune.model().ACCORDO_SERVIZIO_PARTE_COMUNE_GRUPPO.ID_GRUPPO);
  884.             String tableName2 = this.getAccordoServizioParteComuneFieldConverter().toTable(AccordoServizioParteComune.model().ACCORDO_SERVIZIO_PARTE_COMUNE_GRUPPO);
  885.             sqlQueryObject.addWhereCondition(tableName1+".id="+tableName2+".id_gruppo");
  886.             if(!addJoinAccordiToAccordiGruppi) {
  887.                 tableName1 = this.getAccordoServizioParteComuneFieldConverter().toTable(AccordoServizioParteComune.model().ACCORDO_SERVIZIO_PARTE_COMUNE_GRUPPO);
  888.                 tableName2 = this.getAccordoServizioParteComuneFieldConverter().toTable(AccordoServizioParteComune.model());
  889.                 sqlQueryObject.addWhereCondition(tableName1+".id_accordo="+tableName2+".id");
  890.             }
  891.         }

  892.        
  893.         // Check FROM Table necessarie per le join di oggetti annidati dal secondo livello in poi dove pero' non viene poi utilizzato l'oggetto del livello precedente nella espressione
  894.         if(expression.inUseModel(AccordoServizioParteComune.model().PORT_TYPE.OPERATION,false)){
  895.             if(expression.inUseModel(AccordoServizioParteComune.model().PORT_TYPE,false)==false){
  896.                 sqlQueryObject.addFromTable(this.getAccordoServizioParteComuneFieldConverter().toTable(AccordoServizioParteComune.model().PORT_TYPE));
  897.             }
  898.         }
  899.        
  900.         if(expression.inUseModel(AccordoServizioParteComune.model().ACCORDO_SERVIZIO_PARTE_COMUNE_GRUPPO.ID_GRUPPO,false)){
  901.             if(expression.inUseModel(AccordoServizioParteComune.model().ACCORDO_SERVIZIO_PARTE_COMUNE_GRUPPO,false)==false){
  902.                 sqlQueryObject.addFromTable(this.getAccordoServizioParteComuneFieldConverter().toTable(AccordoServizioParteComune.model().ACCORDO_SERVIZIO_PARTE_COMUNE_GRUPPO));
  903.             }
  904.         }
  905.        
  906.     }
  907.    
  908.     protected java.util.List<Object> getRootTablePrimaryKeyValuesEngine(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdAccordoServizioParteComune id) throws NotFoundException, ServiceException, NotImplementedException, Exception{
  909.         // Identificativi
  910.         java.util.List<Object> rootTableIdValues = new java.util.ArrayList<>();
  911.         Long longId = this.findIdAccordoServizioParteComune(jdbcProperties, log, connection, sqlQueryObject.newSQLQueryObject(), id, true);
  912.         rootTableIdValues.add(longId);
  913.         return rootTableIdValues;
  914.     }
  915.    
  916.     protected Map<String, List<IField>> getMapTableToPKColumnEngine() throws NotImplementedException, Exception{
  917.    
  918.         AccordoServizioParteComuneFieldConverter converter = this.getAccordoServizioParteComuneFieldConverter();
  919.         Map<String, List<IField>> mapTableToPKColumn = new java.util.HashMap<>();
  920.         UtilsTemplate<IField> utilities = new UtilsTemplate<>();

  921.         // AccordoServizioParteComune.model()
  922.         mapTableToPKColumn.put(converter.toTable(AccordoServizioParteComune.model()),
  923.             utilities.newList(
  924.                 new CustomField("id", Long.class, "id", converter.toTable(AccordoServizioParteComune.model()))
  925.             ));

  926.         // AccordoServizioParteComune.model().ID_REFERENTE
  927.         mapTableToPKColumn.put(converter.toTable(AccordoServizioParteComune.model().ID_REFERENTE),
  928.             utilities.newList(
  929.                 new CustomField("id", Long.class, "id", converter.toTable(AccordoServizioParteComune.model().ID_REFERENTE))
  930.             ));

  931.         // AccordoServizioParteComune.model().ACCORDO_SERVIZIO_PARTE_COMUNE_AZIONE
  932.         mapTableToPKColumn.put(converter.toTable(AccordoServizioParteComune.model().ACCORDO_SERVIZIO_PARTE_COMUNE_AZIONE),
  933.             utilities.newList(
  934.                 new CustomField("id", Long.class, "id", converter.toTable(AccordoServizioParteComune.model().ACCORDO_SERVIZIO_PARTE_COMUNE_AZIONE))
  935.             ));

  936.         // AccordoServizioParteComune.model().ACCORDO_SERVIZIO_PARTE_COMUNE_AZIONE.ID_ACCORDO_SERVIZIO_PARTE_COMUNE
  937.         mapTableToPKColumn.put(converter.toTable(AccordoServizioParteComune.model().ACCORDO_SERVIZIO_PARTE_COMUNE_AZIONE.ID_ACCORDO_SERVIZIO_PARTE_COMUNE),
  938.             utilities.newList(
  939.                 new CustomField("id", Long.class, "id", converter.toTable(AccordoServizioParteComune.model().ACCORDO_SERVIZIO_PARTE_COMUNE_AZIONE.ID_ACCORDO_SERVIZIO_PARTE_COMUNE))
  940.             ));

  941.         // AccordoServizioParteComune.model().ACCORDO_SERVIZIO_PARTE_COMUNE_AZIONE.ID_ACCORDO_SERVIZIO_PARTE_COMUNE.ID_SOGGETTO
  942.         mapTableToPKColumn.put(converter.toTable(AccordoServizioParteComune.model().ACCORDO_SERVIZIO_PARTE_COMUNE_AZIONE.ID_ACCORDO_SERVIZIO_PARTE_COMUNE.ID_SOGGETTO),
  943.             utilities.newList(
  944.                 new CustomField("id", Long.class, "id", converter.toTable(AccordoServizioParteComune.model().ACCORDO_SERVIZIO_PARTE_COMUNE_AZIONE.ID_ACCORDO_SERVIZIO_PARTE_COMUNE.ID_SOGGETTO))
  945.             ));

  946.         // AccordoServizioParteComune.model().PORT_TYPE
  947.         mapTableToPKColumn.put(converter.toTable(AccordoServizioParteComune.model().PORT_TYPE),
  948.             utilities.newList(
  949.                 new CustomField("id", Long.class, "id", converter.toTable(AccordoServizioParteComune.model().PORT_TYPE))
  950.             ));

  951.         // AccordoServizioParteComune.model().PORT_TYPE.OPERATION
  952.         mapTableToPKColumn.put(converter.toTable(AccordoServizioParteComune.model().PORT_TYPE.OPERATION),
  953.             utilities.newList(
  954.                 new CustomField("id", Long.class, "id", converter.toTable(AccordoServizioParteComune.model().PORT_TYPE.OPERATION))
  955.             ));

  956.         // AccordoServizioParteComune.model().PORT_TYPE.OPERATION.ID_PORT_TYPE
  957.         mapTableToPKColumn.put(converter.toTable(AccordoServizioParteComune.model().PORT_TYPE.OPERATION.ID_PORT_TYPE),
  958.             utilities.newList(
  959.                 new CustomField("id", Long.class, "id", converter.toTable(AccordoServizioParteComune.model().PORT_TYPE.OPERATION.ID_PORT_TYPE))
  960.             ));

  961.         // AccordoServizioParteComune.model().PORT_TYPE.OPERATION.ID_PORT_TYPE.ID_ACCORDO_SERVIZIO_PARTE_COMUNE
  962.         mapTableToPKColumn.put(converter.toTable(AccordoServizioParteComune.model().PORT_TYPE.OPERATION.ID_PORT_TYPE.ID_ACCORDO_SERVIZIO_PARTE_COMUNE),
  963.             utilities.newList(
  964.                 new CustomField("id", Long.class, "id", converter.toTable(AccordoServizioParteComune.model().PORT_TYPE.OPERATION.ID_PORT_TYPE.ID_ACCORDO_SERVIZIO_PARTE_COMUNE))
  965.             ));

  966.         // AccordoServizioParteComune.model().PORT_TYPE.OPERATION.ID_PORT_TYPE.ID_ACCORDO_SERVIZIO_PARTE_COMUNE.ID_SOGGETTO
  967.         mapTableToPKColumn.put(converter.toTable(AccordoServizioParteComune.model().PORT_TYPE.OPERATION.ID_PORT_TYPE.ID_ACCORDO_SERVIZIO_PARTE_COMUNE.ID_SOGGETTO),
  968.             utilities.newList(
  969.                 new CustomField("id", Long.class, "id", converter.toTable(AccordoServizioParteComune.model().PORT_TYPE.OPERATION.ID_PORT_TYPE.ID_ACCORDO_SERVIZIO_PARTE_COMUNE.ID_SOGGETTO))
  970.             ));

  971.         // AccordoServizioParteComune.model().PORT_TYPE.ID_ACCORDO_SERVIZIO_PARTE_COMUNE
  972.         mapTableToPKColumn.put(converter.toTable(AccordoServizioParteComune.model().PORT_TYPE.ID_ACCORDO_SERVIZIO_PARTE_COMUNE),
  973.             utilities.newList(
  974.                 new CustomField("id", Long.class, "id", converter.toTable(AccordoServizioParteComune.model().PORT_TYPE.ID_ACCORDO_SERVIZIO_PARTE_COMUNE))
  975.             ));

  976.         // AccordoServizioParteComune.model().PORT_TYPE.ID_ACCORDO_SERVIZIO_PARTE_COMUNE.ID_SOGGETTO
  977.         mapTableToPKColumn.put(converter.toTable(AccordoServizioParteComune.model().PORT_TYPE.ID_ACCORDO_SERVIZIO_PARTE_COMUNE.ID_SOGGETTO),
  978.             utilities.newList(
  979.                 new CustomField("id", Long.class, "id", converter.toTable(AccordoServizioParteComune.model().PORT_TYPE.ID_ACCORDO_SERVIZIO_PARTE_COMUNE.ID_SOGGETTO))
  980.             ));

  981.         // AccordoServizioParteComune.model().RESOURCE
  982.         mapTableToPKColumn.put(converter.toTable(AccordoServizioParteComune.model().RESOURCE),
  983.             utilities.newList(
  984.                 new CustomField("id", Long.class, "id", converter.toTable(AccordoServizioParteComune.model().RESOURCE))
  985.             ));

  986.         // AccordoServizioParteComune.model().RESOURCE.ID_ACCORDO_SERVIZIO_PARTE_COMUNE
  987.         mapTableToPKColumn.put(converter.toTable(AccordoServizioParteComune.model().RESOURCE.ID_ACCORDO_SERVIZIO_PARTE_COMUNE),
  988.             utilities.newList(
  989.                 new CustomField("id", Long.class, "id", converter.toTable(AccordoServizioParteComune.model().RESOURCE.ID_ACCORDO_SERVIZIO_PARTE_COMUNE))
  990.             ));

  991.         // AccordoServizioParteComune.model().RESOURCE.ID_ACCORDO_SERVIZIO_PARTE_COMUNE.ID_SOGGETTO
  992.         mapTableToPKColumn.put(converter.toTable(AccordoServizioParteComune.model().RESOURCE.ID_ACCORDO_SERVIZIO_PARTE_COMUNE.ID_SOGGETTO),
  993.             utilities.newList(
  994.                 new CustomField("id", Long.class, "id", converter.toTable(AccordoServizioParteComune.model().RESOURCE.ID_ACCORDO_SERVIZIO_PARTE_COMUNE.ID_SOGGETTO))
  995.             ));

  996.         // AccordoServizioParteComune.model().ACCORDO_SERVIZIO_PARTE_COMUNE_GRUPPO
  997.         mapTableToPKColumn.put(converter.toTable(AccordoServizioParteComune.model().ACCORDO_SERVIZIO_PARTE_COMUNE_GRUPPO),
  998.             utilities.newList(
  999.                 new CustomField("id", Long.class, "id", converter.toTable(AccordoServizioParteComune.model().ACCORDO_SERVIZIO_PARTE_COMUNE_GRUPPO))
  1000.             ));

  1001.         // AccordoServizioParteComune.model().ACCORDO_SERVIZIO_PARTE_COMUNE_GRUPPO.ID_GRUPPO
  1002.         mapTableToPKColumn.put(converter.toTable(AccordoServizioParteComune.model().ACCORDO_SERVIZIO_PARTE_COMUNE_GRUPPO.ID_GRUPPO),
  1003.             utilities.newList(
  1004.                 new CustomField("id", Long.class, "id", converter.toTable(AccordoServizioParteComune.model().ACCORDO_SERVIZIO_PARTE_COMUNE_GRUPPO.ID_GRUPPO))
  1005.             ));

  1006.        
  1007.         return mapTableToPKColumn;      
  1008.     }
  1009.    
  1010.     @Override
  1011.     public List<Long> findAllTableIds(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCPaginatedExpression paginatedExpression) throws ServiceException, NotImplementedException, Exception {
  1012.        
  1013.         List<Long> list = new ArrayList<Long>();

  1014.         sqlQueryObject.setSelectDistinct(true);
  1015.         sqlQueryObject.setANDLogicOperator(true);
  1016.         sqlQueryObject.addSelectField(this.getAccordoServizioParteComuneFieldConverter().toTable(AccordoServizioParteComune.model())+".id");
  1017.         Class<?> objectIdClass = Long.class;
  1018.        
  1019.         List<Object> listaQuery = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareFindAll(jdbcProperties, log, connection, sqlQueryObject, paginatedExpression,
  1020.                                                 this.getAccordoServizioParteComuneFieldConverter(), AccordoServizioParteComune.model());
  1021.        
  1022.         joinEngine(paginatedExpression,sqlQueryObject);
  1023.        
  1024.         List<Object> listObjects = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.findAll(jdbcProperties, log, connection, sqlQueryObject, paginatedExpression,
  1025.                                                                             this.getAccordoServizioParteComuneFieldConverter(), AccordoServizioParteComune.model(), objectIdClass, listaQuery);
  1026.         for(Object object: listObjects) {
  1027.             list.add((Long)object);
  1028.         }

  1029.         return list;
  1030.        
  1031.     }
  1032.    
  1033.     @Override
  1034.     public long findTableId(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCExpression expression) throws ServiceException, NotFoundException, MultipleResultException, NotImplementedException, Exception {
  1035.    
  1036.         sqlQueryObject.setSelectDistinct(true);
  1037.         sqlQueryObject.setANDLogicOperator(true);
  1038.         sqlQueryObject.addSelectField(this.getAccordoServizioParteComuneFieldConverter().toTable(AccordoServizioParteComune.model())+".id");
  1039.         Class<?> objectIdClass = Long.class;
  1040.        
  1041.         List<Object> listaQuery = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareFind(jdbcProperties, log, connection, sqlQueryObject, expression,
  1042.                                                 this.getAccordoServizioParteComuneFieldConverter(), AccordoServizioParteComune.model());
  1043.        
  1044.         joinEngine(expression,sqlQueryObject);

  1045.         Object res = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.find(jdbcProperties, log, connection, sqlQueryObject, expression,
  1046.                                                         this.getAccordoServizioParteComuneFieldConverter(), AccordoServizioParteComune.model(), objectIdClass, listaQuery);
  1047.         if(res!=null && (((Long) res).longValue()>0) ){
  1048.             return ((Long) res).longValue();
  1049.         }
  1050.         else{
  1051.             throw org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.newNotFoundException();
  1052.         }
  1053.        
  1054.     }

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

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

  1060.         InUse inUse = new InUse();
  1061.         inUse.setInUse(false);
  1062.        
  1063.         /*
  1064.          * TODO: implement code that checks whether the object identified by the id parameter is used by other objects
  1065.         */
  1066.        
  1067.         // Delete this line when you have implemented the method
  1068.         int throwNotImplemented = 1;
  1069.         if(throwNotImplemented==1){
  1070.                 throw new NotImplementedException("NotImplemented");
  1071.         }
  1072.         // Delete this line when you have implemented the method

  1073.         return inUse;

  1074.     }
  1075.    
  1076.     @Override
  1077.     public IdAccordoServizioParteComune findId(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId, boolean throwNotFound)
  1078.             throws NotFoundException, ServiceException, NotImplementedException, Exception {
  1079.        
  1080.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  1081.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);

  1082.         ISQLQueryObject sqlQueryObjectGet = sqlQueryObject.newSQLQueryObject();

  1083.         // Object _accordoServizioParteComune
  1084.         sqlQueryObjectGet.addFromTable(this.getAccordoServizioParteComuneFieldConverter().toTable(AccordoServizioParteComune.model()));
  1085.         sqlQueryObjectGet.addSelectField(this.getAccordoServizioParteComuneFieldConverter().toColumn(AccordoServizioParteComune.model().NOME,true));
  1086.         sqlQueryObjectGet.addSelectField(this.getAccordoServizioParteComuneFieldConverter().toColumn(AccordoServizioParteComune.model().VERSIONE,true));
  1087.         sqlQueryObjectGet.addSelectField("id_referente");
  1088.         sqlQueryObjectGet.addSelectField(this.getAccordoServizioParteComuneFieldConverter().toColumn(AccordoServizioParteComune.model().SERVICE_BINDING,true));
  1089.         sqlQueryObjectGet.setANDLogicOperator(true);
  1090.         sqlQueryObjectGet.addWhereCondition("id=?");

  1091.         // Recupero _accordoServizioParteComune
  1092.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject [] searchParams_accordoServizioParteComune = new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject [] {
  1093.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(tableId,Long.class)
  1094.         };
  1095.         List<Class<?>> listaFieldIdReturnType_accordoServizioParteComune = new ArrayList<Class<?>>();
  1096.         listaFieldIdReturnType_accordoServizioParteComune.add(String.class);
  1097.         listaFieldIdReturnType_accordoServizioParteComune.add(Integer.class);
  1098.         listaFieldIdReturnType_accordoServizioParteComune.add(Long.class);
  1099.         listaFieldIdReturnType_accordoServizioParteComune.add(String.class);
  1100.         org.openspcoop2.core.commons.search.IdAccordoServizioParteComune id_accordoServizioParteComune = null;
  1101.         List<Object> listaFieldId_accordoServizioParteComune = jdbcUtilities.executeQuerySingleResult(sqlQueryObjectGet.createSQLQuery(), jdbcProperties.isShowSql(),
  1102.                 listaFieldIdReturnType_accordoServizioParteComune, searchParams_accordoServizioParteComune);
  1103.         if(listaFieldId_accordoServizioParteComune==null || listaFieldId_accordoServizioParteComune.size()<=0){
  1104.             if(throwNotFound){
  1105.                 throw org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.newNotFoundException();
  1106.             }
  1107.         }
  1108.         else{
  1109.             // set _accordoServizioParteComune
  1110.             id_accordoServizioParteComune = new org.openspcoop2.core.commons.search.IdAccordoServizioParteComune();
  1111.             id_accordoServizioParteComune.setNome((String)listaFieldId_accordoServizioParteComune.get(0));
  1112.             id_accordoServizioParteComune.setVersione((Integer)listaFieldId_accordoServizioParteComune.get(1));
  1113.             Long idSoggettoFK = (Long) listaFieldId_accordoServizioParteComune.get(2);
  1114.             id_accordoServizioParteComune.setServiceBinding((String)listaFieldId_accordoServizioParteComune.get(3));
  1115.             id_accordoServizioParteComune.
  1116.                 setIdSoggetto(((IDBSoggettoServiceSearch)this.getServiceManager(connection, jdbcProperties, log).
  1117.                         getSoggettoServiceSearch()).findId(idSoggettoFK, true));
  1118.         }
  1119.        
  1120.         return id_accordoServizioParteComune;
  1121.        
  1122.     }

  1123.     @Override
  1124.     public Long findTableId(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdAccordoServizioParteComune id, boolean throwNotFound)
  1125.             throws NotFoundException, ServiceException, NotImplementedException, Exception {
  1126.    
  1127.         return this.findIdAccordoServizioParteComune(jdbcProperties,log,connection,sqlQueryObject,id,throwNotFound);
  1128.            
  1129.     }
  1130.    
  1131.     @Override
  1132.     public List<List<Object>> nativeQuery(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  1133.                                             String sql,List<Class<?>> returnClassTypes,Object ... param) throws ServiceException,NotFoundException,NotImplementedException,Exception{
  1134.        
  1135.         return org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.nativeQuery(jdbcProperties, log, connection, sqlQueryObject,
  1136.                                                                                             sql,returnClassTypes,param);
  1137.                                                        
  1138.     }
  1139.    
  1140.     protected Long findIdAccordoServizioParteComune(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdAccordoServizioParteComune id, boolean throwNotFound) throws NotFoundException, ServiceException, NotImplementedException, Exception {

  1141.         if(jdbcProperties==null) {
  1142.             throw new ServiceException("Param jdbcProperties is null");
  1143.         }
  1144.         if(sqlQueryObject==null) {
  1145.             throw new ServiceException("Param sqlQueryObject is null");
  1146.         }
  1147.         if(id==null) {
  1148.             throw new ServiceException("Param id is null");
  1149.         }
  1150.        
  1151.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  1152.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);

  1153.         ISQLQueryObject sqlQueryObjectGet = sqlQueryObject.newSQLQueryObject();

  1154.         // found idSoggetto
  1155. //      if(id.getIdSoggetto()==null){
  1156. //          throw new ServiceException("Id soggetto non fornito");
  1157. //      }
  1158.         Soggetto soggetto = null;
  1159.        
  1160.         // Object _accordoServizioParteComune
  1161.         sqlQueryObjectGet.addFromTable(this.getAccordoServizioParteComuneFieldConverter().toTable(AccordoServizioParteComune.model()));
  1162.         sqlQueryObjectGet.addSelectField("id");
  1163.         sqlQueryObjectGet.setANDLogicOperator(true);
  1164.         sqlQueryObjectGet.setSelectDistinct(true);
  1165.         sqlQueryObjectGet.addWhereCondition(this.getAccordoServizioParteComuneFieldConverter().toColumn(AccordoServizioParteComune.model().NOME,true)+"=?");
  1166.         if(id.getVersione()!=null)
  1167.             sqlQueryObjectGet.addWhereCondition(this.getAccordoServizioParteComuneFieldConverter().toColumn(AccordoServizioParteComune.model().VERSIONE,true)+"=?");
  1168.         else
  1169.             sqlQueryObjectGet.addWhereCondition(this.getAccordoServizioParteComuneFieldConverter().toColumn(AccordoServizioParteComune.model().VERSIONE,true)+" is null");
  1170.         if(id.getIdSoggetto()==null){
  1171.             sqlQueryObjectGet.addWhereCondition("( (id_referente is null) OR (id_referente<=0) )");
  1172.         }else{
  1173.             sqlQueryObjectGet.addWhereCondition("id_referente=?");
  1174.             soggetto = this.getServiceManager(connection, jdbcProperties, log).getSoggettoServiceSearch().get(id.getIdSoggetto());
  1175.         }
  1176.        

  1177.         // Recupero _accordoServizioParteComune
  1178.         List<org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject> listJDBCObject = new ArrayList<org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject>();
  1179.         listJDBCObject.add(new JDBCObject(id.getNome(), String.class));
  1180.         if(id.getVersione()!=null){
  1181.             listJDBCObject.add(new JDBCObject(id.getVersione(), Integer.class));
  1182.         }
  1183.         if(soggetto!=null){
  1184.             listJDBCObject.add(new JDBCObject(soggetto.getId(), Long.class));
  1185.         }
  1186.         Long id_accordoServizioParteComune = null;
  1187.         try{
  1188.             id_accordoServizioParteComune = (Long) jdbcUtilities.executeQuerySingleResult(sqlQueryObjectGet.createSQLQuery(), jdbcProperties.isShowSql(),
  1189.                         Long.class, listJDBCObject.toArray(new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject [1]));
  1190.         }catch(NotFoundException notFound){
  1191.             if(throwNotFound){
  1192.                 throw new NotFoundException(notFound);
  1193.             }
  1194.         }
  1195.         if(id_accordoServizioParteComune==null || id_accordoServizioParteComune<=0){
  1196.             if(throwNotFound){
  1197.                 throw org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.newNotFoundException();
  1198.             }
  1199.         }
  1200.        
  1201.         return id_accordoServizioParteComune;
  1202.     }
  1203. }