JDBCSoggettoRuoloServiceSearchImpl.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */
  20. package org.openspcoop2.core.commons.search.dao.jdbc;

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

  25. import org.openspcoop2.core.commons.search.IdRuolo;
  26. import org.openspcoop2.core.commons.search.IdSoggetto;
  27. import org.openspcoop2.core.commons.search.IdSoggettoRuolo;
  28. import org.openspcoop2.core.commons.search.Ruolo;
  29. import org.openspcoop2.core.commons.search.Soggetto;
  30. import org.openspcoop2.core.commons.search.SoggettoRuolo;
  31. import org.openspcoop2.core.commons.search.dao.IDBRuoloServiceSearch;
  32. import org.openspcoop2.core.commons.search.dao.IDBSoggettoServiceSearch;
  33. import org.openspcoop2.core.commons.search.dao.jdbc.converter.SoggettoRuoloFieldConverter;
  34. import org.openspcoop2.core.commons.search.dao.jdbc.fetch.SoggettoRuoloFetch;
  35. import org.openspcoop2.generic_project.beans.CustomField;
  36. import org.openspcoop2.generic_project.beans.FunctionField;
  37. import org.openspcoop2.generic_project.beans.IField;
  38. import org.openspcoop2.generic_project.beans.InUse;
  39. import org.openspcoop2.generic_project.beans.NonNegativeNumber;
  40. import org.openspcoop2.generic_project.beans.Union;
  41. import org.openspcoop2.generic_project.beans.UnionExpression;
  42. import org.openspcoop2.generic_project.dao.jdbc.IJDBCServiceSearchWithId;
  43. import org.openspcoop2.generic_project.dao.jdbc.JDBCExpression;
  44. import org.openspcoop2.generic_project.dao.jdbc.JDBCPaginatedExpression;
  45. import org.openspcoop2.generic_project.dao.jdbc.JDBCServiceManagerProperties;
  46. import org.openspcoop2.generic_project.dao.jdbc.utils.IJDBCFetch;
  47. import org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject;
  48. import org.openspcoop2.generic_project.exception.MultipleResultException;
  49. import org.openspcoop2.generic_project.exception.NotFoundException;
  50. import org.openspcoop2.generic_project.exception.NotImplementedException;
  51. import org.openspcoop2.generic_project.exception.ServiceException;
  52. import org.openspcoop2.generic_project.expression.IExpression;
  53. import org.openspcoop2.generic_project.expression.impl.sql.ISQLFieldConverter;
  54. import org.openspcoop2.generic_project.utils.UtilsTemplate;
  55. import org.openspcoop2.utils.sql.ISQLQueryObject;
  56. import org.slf4j.Logger;

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

  65.     private SoggettoRuoloFieldConverter _soggettoRuoloFieldConverter = null;
  66.     public SoggettoRuoloFieldConverter getSoggettoRuoloFieldConverter() {
  67.         if(this._soggettoRuoloFieldConverter==null){
  68.             this._soggettoRuoloFieldConverter = new SoggettoRuoloFieldConverter(this.jdbcServiceManager.getJdbcProperties().getDatabaseType());
  69.         }      
  70.         return this._soggettoRuoloFieldConverter;
  71.     }
  72.     @Override
  73.     public ISQLFieldConverter getFieldConverter() {
  74.         return this.getSoggettoRuoloFieldConverter();
  75.     }
  76.    
  77.     private SoggettoRuoloFetch soggettoRuoloFetch = new SoggettoRuoloFetch();
  78.     public SoggettoRuoloFetch getSoggettoRuoloFetch() {
  79.         return this.soggettoRuoloFetch;
  80.     }
  81.     @Override
  82.     public IJDBCFetch getFetch() {
  83.         return getSoggettoRuoloFetch();
  84.     }
  85.    
  86.    
  87.     private JDBCServiceManager jdbcServiceManager = null;

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

  101.     @Override
  102.     public IdSoggettoRuolo convertToId(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, SoggettoRuolo soggettoRuolo) throws NotImplementedException, ServiceException, Exception{
  103.    
  104.         IdSoggettoRuolo idSoggettoRuolo = new IdSoggettoRuolo();
  105.         idSoggettoRuolo.setIdRuolo(soggettoRuolo.getIdRuolo());
  106.         idSoggettoRuolo.setIdSoggetto(soggettoRuolo.getIdSoggetto());
  107.         return idSoggettoRuolo;
  108.     }
  109.    
  110.     @Override
  111.     public SoggettoRuolo get(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdSoggettoRuolo id, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotFoundException, MultipleResultException, NotImplementedException, ServiceException,Exception {
  112.         Long id_soggettoRuolo = ( (id!=null && id.getId()!=null && id.getId()>0) ? id.getId() : this.findIdSoggettoRuolo(jdbcProperties, log, connection, sqlQueryObject, id, true));
  113.         return this.getEngine(jdbcProperties, log, connection, sqlQueryObject, id_soggettoRuolo,idMappingResolutionBehaviour);
  114.        
  115.        
  116.     }
  117.    
  118.     @Override
  119.     public boolean exists(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdSoggettoRuolo id) throws MultipleResultException, NotImplementedException, ServiceException,Exception {

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

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

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

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

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

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

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

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

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

  188.     @Override
  189.     public InUse inUse(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdSoggettoRuolo id) throws NotFoundException, NotImplementedException, ServiceException,Exception {
  190.        
  191.         Long id_soggettoRuolo = this.findIdSoggettoRuolo(jdbcProperties, log, connection, sqlQueryObject, id, true);
  192.         return this.inUseEngine(jdbcProperties, log, connection, sqlQueryObject, id_soggettoRuolo);
  193.        
  194.     }

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

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

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

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

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



  369.     // -- ConstructorExpression

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


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

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

  407.     @Override
  408.     public void mappingTableIds(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdSoggettoRuolo id, SoggettoRuolo obj) throws NotFoundException,NotImplementedException,ServiceException,Exception{
  409.         _mappingTableIds(jdbcProperties,log,connection,sqlQueryObject,obj,
  410.                 this.get(jdbcProperties,log,connection,sqlQueryObject,id,null));
  411.     }
  412.    
  413.     @Override
  414.     public void mappingTableIds(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId, SoggettoRuolo obj) throws NotFoundException,NotImplementedException,ServiceException,Exception{
  415.         _mappingTableIds(jdbcProperties,log,connection,sqlQueryObject,obj,
  416.                 this.get(jdbcProperties,log,connection,sqlQueryObject,tableId,null));
  417.     }
  418.     private void _mappingTableIds(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, SoggettoRuolo obj, SoggettoRuolo imgSaved) throws NotFoundException,NotImplementedException,ServiceException,Exception{
  419.         if(imgSaved==null){
  420.             return;
  421.         }
  422.         obj.setId(imgSaved.getId());
  423.         if(obj.getIdRuolo()!=null &&
  424.                 imgSaved.getIdRuolo()!=null){
  425.             obj.getIdRuolo().setId(imgSaved.getIdRuolo().getId());
  426.         }
  427.         if(obj.getIdSoggetto()!=null &&
  428.                 imgSaved.getIdSoggetto()!=null){
  429.             obj.getIdSoggetto().setId(imgSaved.getIdSoggetto().getId());
  430.         }

  431.     }
  432.    
  433.     @Override
  434.     public SoggettoRuolo get(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotFoundException, MultipleResultException, NotImplementedException, ServiceException, Exception {
  435.         return this.getEngine(jdbcProperties, log, connection, sqlQueryObject, Long.valueOf(tableId), idMappingResolutionBehaviour);
  436.     }
  437.    
  438.     private SoggettoRuolo getEngine(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, Long tableId, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotFoundException, MultipleResultException, NotImplementedException, ServiceException, Exception {
  439.    
  440.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  441.                     new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);
  442.        
  443.         ISQLQueryObject sqlQueryObjectGet = sqlQueryObject.newSQLQueryObject();
  444.                
  445.         SoggettoRuolo soggettoRuolo = new SoggettoRuolo();
  446.        

  447.         // Object soggettoRuolo
  448.         ISQLQueryObject sqlQueryObjectGet_soggettoRuolo = sqlQueryObjectGet.newSQLQueryObject();
  449.         sqlQueryObjectGet_soggettoRuolo.setANDLogicOperator(true);
  450.         sqlQueryObjectGet_soggettoRuolo.addFromTable(this.getSoggettoRuoloFieldConverter().toTable(SoggettoRuolo.model()));
  451.         sqlQueryObjectGet_soggettoRuolo.addSelectField("id");
  452.         sqlQueryObjectGet_soggettoRuolo.addWhereCondition("id=?");

  453.         // Get soggettoRuolo
  454.         soggettoRuolo = (SoggettoRuolo) jdbcUtilities.executeQuerySingleResult(sqlQueryObjectGet_soggettoRuolo.createSQLQuery(), jdbcProperties.isShowSql(), SoggettoRuolo.model(), this.getSoggettoRuoloFetch(),
  455.             new JDBCObject(tableId,Long.class));


  456.         if(idMappingResolutionBehaviour==null ||
  457.             (org.openspcoop2.generic_project.beans.IDMappingBehaviour.ENABLED.equals(idMappingResolutionBehaviour) || org.openspcoop2.generic_project.beans.IDMappingBehaviour.USE_TABLE_ID.equals(idMappingResolutionBehaviour))
  458.         ){
  459.             // Object _soggettoRuolo_ruolo (recupero id)
  460.             ISQLQueryObject sqlQueryObjectGet_soggettoRuolo_ruolo_readFkId = sqlQueryObjectGet.newSQLQueryObject();
  461.             sqlQueryObjectGet_soggettoRuolo_ruolo_readFkId.addFromTable(this.getSoggettoRuoloFieldConverter().toTable(org.openspcoop2.core.commons.search.SoggettoRuolo.model()));
  462.             sqlQueryObjectGet_soggettoRuolo_ruolo_readFkId.addSelectField("id_ruolo");
  463.             sqlQueryObjectGet_soggettoRuolo_ruolo_readFkId.addWhereCondition("id=?");
  464.             sqlQueryObjectGet_soggettoRuolo_ruolo_readFkId.setANDLogicOperator(true);
  465.             Long idFK_soggettoRuolo_ruolo = (Long) jdbcUtilities.executeQuerySingleResult(sqlQueryObjectGet_soggettoRuolo_ruolo_readFkId.createSQLQuery(), jdbcProperties.isShowSql(),Long.class,
  466.                     new JDBCObject(soggettoRuolo.getId(),Long.class));
  467.            
  468.             org.openspcoop2.core.commons.search.IdRuolo id_soggettoRuolo_ruolo = null;
  469.             if(idMappingResolutionBehaviour==null || org.openspcoop2.generic_project.beans.IDMappingBehaviour.ENABLED.equals(idMappingResolutionBehaviour)){
  470.                 id_soggettoRuolo_ruolo = ((JDBCRuoloServiceSearch)(this.getServiceManager(connection, jdbcProperties, log).getRuoloServiceSearch())).findId(idFK_soggettoRuolo_ruolo, false);
  471.             }else{
  472.                 id_soggettoRuolo_ruolo = new org.openspcoop2.core.commons.search.IdRuolo();
  473.             }
  474.             id_soggettoRuolo_ruolo.setId(idFK_soggettoRuolo_ruolo);
  475.             soggettoRuolo.setIdRuolo(id_soggettoRuolo_ruolo);
  476.         }

  477.         if(idMappingResolutionBehaviour==null ||
  478.             (org.openspcoop2.generic_project.beans.IDMappingBehaviour.ENABLED.equals(idMappingResolutionBehaviour) || org.openspcoop2.generic_project.beans.IDMappingBehaviour.USE_TABLE_ID.equals(idMappingResolutionBehaviour))
  479.         ){
  480.             // Object _soggettoRuolo_soggetto (recupero id)
  481.             ISQLQueryObject sqlQueryObjectGet_soggettoRuolo_soggetto_readFkId = sqlQueryObjectGet.newSQLQueryObject();
  482.             sqlQueryObjectGet_soggettoRuolo_soggetto_readFkId.addFromTable(this.getSoggettoRuoloFieldConverter().toTable(org.openspcoop2.core.commons.search.SoggettoRuolo.model()));
  483.             sqlQueryObjectGet_soggettoRuolo_soggetto_readFkId.addSelectField("id_soggetto");
  484.             sqlQueryObjectGet_soggettoRuolo_soggetto_readFkId.addWhereCondition("id=?");
  485.             sqlQueryObjectGet_soggettoRuolo_soggetto_readFkId.setANDLogicOperator(true);
  486.             Long idFK_soggettoRuolo_soggetto = (Long) jdbcUtilities.executeQuerySingleResult(sqlQueryObjectGet_soggettoRuolo_soggetto_readFkId.createSQLQuery(), jdbcProperties.isShowSql(),Long.class,
  487.                     new JDBCObject(soggettoRuolo.getId(),Long.class));
  488.            
  489.             org.openspcoop2.core.commons.search.IdSoggetto id_soggettoRuolo_soggetto = null;
  490.             if(idMappingResolutionBehaviour==null || org.openspcoop2.generic_project.beans.IDMappingBehaviour.ENABLED.equals(idMappingResolutionBehaviour)){
  491.                 id_soggettoRuolo_soggetto = ((JDBCSoggettoServiceSearch)(this.getServiceManager(connection, jdbcProperties, log).getSoggettoServiceSearch())).findId(idFK_soggettoRuolo_soggetto, false);
  492.             }else{
  493.                 id_soggettoRuolo_soggetto = new org.openspcoop2.core.commons.search.IdSoggetto();
  494.             }
  495.             id_soggettoRuolo_soggetto.setId(idFK_soggettoRuolo_soggetto);
  496.             soggettoRuolo.setIdSoggetto(id_soggettoRuolo_soggetto);
  497.         }

  498.         return soggettoRuolo;  
  499.    
  500.     }
  501.    
  502.     @Override
  503.     public boolean exists(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId) throws MultipleResultException, NotImplementedException, ServiceException, Exception {
  504.         return this._exists(jdbcProperties, log, connection, sqlQueryObject, Long.valueOf(tableId));
  505.     }
  506.    
  507.     private boolean _exists(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, Long tableId) throws MultipleResultException, NotImplementedException, ServiceException, Exception {
  508.    
  509.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  510.                     new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);
  511.                
  512.         boolean existsSoggettoRuolo = false;

  513.         sqlQueryObject = sqlQueryObject.newSQLQueryObject();
  514.         sqlQueryObject.setANDLogicOperator(true);

  515.         sqlQueryObject.addWhereCondition("id=?");


  516.         // Exists soggettoRuolo
  517.         existsSoggettoRuolo = jdbcUtilities.exists(sqlQueryObject.createSQLQuery(), jdbcProperties.isShowSql(),
  518.             new JDBCObject(tableId,Long.class));

  519.        
  520.         return existsSoggettoRuolo;
  521.    
  522.     }
  523.    
  524.     private void joinEngine(IExpression expression, ISQLQueryObject sqlQueryObject) throws NotImplementedException, ServiceException, Exception{
  525.    
  526.         if(expression.inUseModel(SoggettoRuolo.model().ID_RUOLO,false)){
  527.             String tableName1 = this.getSoggettoRuoloFieldConverter().toAliasTable(SoggettoRuolo.model());
  528.             String tableName2 = this.getSoggettoRuoloFieldConverter().toAliasTable(SoggettoRuolo.model().ID_RUOLO);
  529.             sqlQueryObject.addWhereCondition(tableName1+".id_ruolo="+tableName2+".id");
  530.         }
  531.         if(expression.inUseModel(SoggettoRuolo.model().ID_SOGGETTO,false)){
  532.             String tableName1 = this.getSoggettoRuoloFieldConverter().toAliasTable(SoggettoRuolo.model());
  533.             String tableName2 = this.getSoggettoRuoloFieldConverter().toAliasTable(SoggettoRuolo.model().ID_SOGGETTO);
  534.             sqlQueryObject.addWhereCondition(tableName1+".id_soggetto="+tableName2+".id");
  535.         }
  536.    
  537.     }
  538.    
  539.     protected java.util.List<Object> getRootTablePrimaryKeyValuesEngine(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdSoggettoRuolo id) throws NotFoundException, ServiceException, NotImplementedException, Exception{
  540.         // Identificativi
  541.         java.util.List<Object> rootTableIdValues = new java.util.ArrayList<>();
  542.         Long longId = this.findIdSoggettoRuolo(jdbcProperties, log, connection, sqlQueryObject.newSQLQueryObject(), id, true);
  543.         rootTableIdValues.add(longId);
  544.         return rootTableIdValues;
  545.     }
  546.    
  547.     protected Map<String, List<IField>> getMapTableToPKColumnEngine() throws NotImplementedException, Exception{
  548.    
  549.         SoggettoRuoloFieldConverter converter = this.getSoggettoRuoloFieldConverter();
  550.         Map<String, List<IField>> mapTableToPKColumn = new java.util.HashMap<>();
  551.         UtilsTemplate<IField> utilities = new UtilsTemplate<>();

  552.         // SoggettoRuolo.model()
  553.         mapTableToPKColumn.put(converter.toTable(SoggettoRuolo.model()),
  554.             utilities.newList(
  555.                 new CustomField("id", Long.class, "id", converter.toTable(SoggettoRuolo.model()))
  556.             ));

  557.         // SoggettoRuolo.model().ID_RUOLO
  558.         mapTableToPKColumn.put(converter.toTable(SoggettoRuolo.model().ID_RUOLO),
  559.             utilities.newList(
  560.                 new CustomField("id", Long.class, "id", converter.toTable(SoggettoRuolo.model().ID_RUOLO))
  561.             ));

  562.         // SoggettoRuolo.model().ID_SOGGETTO
  563.         mapTableToPKColumn.put(converter.toTable(SoggettoRuolo.model().ID_SOGGETTO),
  564.             utilities.newList(
  565.                 new CustomField("id", Long.class, "id", converter.toTable(SoggettoRuolo.model().ID_SOGGETTO))
  566.             ));

  567.         return mapTableToPKColumn;      
  568.     }
  569.    
  570.     @Override
  571.     public List<Long> findAllTableIds(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCPaginatedExpression paginatedExpression) throws ServiceException, NotImplementedException, Exception {
  572.        
  573.         List<Long> list = new ArrayList<Long>();

  574.         sqlQueryObject.setSelectDistinct(true);
  575.         sqlQueryObject.setANDLogicOperator(true);
  576.         sqlQueryObject.addSelectField(this.getSoggettoRuoloFieldConverter().toTable(SoggettoRuolo.model())+".id");
  577.         Class<?> objectIdClass = Long.class;
  578.        
  579.         List<Object> listaQuery = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareFindAll(jdbcProperties, log, connection, sqlQueryObject, paginatedExpression,
  580.                                                 this.getSoggettoRuoloFieldConverter(), SoggettoRuolo.model());
  581.        
  582.         joinEngine(paginatedExpression,sqlQueryObject);
  583.        
  584.         List<Object> listObjects = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.findAll(jdbcProperties, log, connection, sqlQueryObject, paginatedExpression,
  585.                                                                             this.getSoggettoRuoloFieldConverter(), SoggettoRuolo.model(), objectIdClass, listaQuery);
  586.         for(Object object: listObjects) {
  587.             list.add((Long)object);
  588.         }

  589.         return list;
  590.        
  591.     }
  592.    
  593.     @Override
  594.     public long findTableId(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCExpression expression) throws ServiceException, NotFoundException, MultipleResultException, NotImplementedException, Exception {
  595.    
  596.         sqlQueryObject.setSelectDistinct(true);
  597.         sqlQueryObject.setANDLogicOperator(true);
  598.         sqlQueryObject.addSelectField(this.getSoggettoRuoloFieldConverter().toTable(SoggettoRuolo.model())+".id");
  599.         Class<?> objectIdClass = Long.class;
  600.        
  601.         List<Object> listaQuery = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareFind(jdbcProperties, log, connection, sqlQueryObject, expression,
  602.                                                 this.getSoggettoRuoloFieldConverter(), SoggettoRuolo.model());
  603.        
  604.         joinEngine(expression,sqlQueryObject);

  605.         Object res = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.find(jdbcProperties, log, connection, sqlQueryObject, expression,
  606.                                                         this.getSoggettoRuoloFieldConverter(), SoggettoRuolo.model(), objectIdClass, listaQuery);
  607.         if(res!=null && (((Long) res).longValue()>0) ){
  608.             return ((Long) res).longValue();
  609.         }
  610.         else{
  611.             throw org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.newNotFoundException();
  612.         }
  613.        
  614.     }

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

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

  620.         InUse inUse = new InUse();
  621.         inUse.setInUse(false);
  622.        
  623.         /*
  624.          * TODO: implement code that checks whether the object identified by the id parameter is used by other objects
  625.         */
  626.        
  627.         // Delete this line when you have implemented the method
  628.         int throwNotImplemented = 1;
  629.         if(throwNotImplemented==1){
  630.                 throw new NotImplementedException("NotImplemented");
  631.         }
  632.         // Delete this line when you have implemented the method

  633.         return inUse;

  634.     }
  635.    
  636.     @Override
  637.     public IdSoggettoRuolo findId(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId, boolean throwNotFound)
  638.             throws NotFoundException, ServiceException, NotImplementedException, Exception {
  639.        
  640.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  641.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);

  642.         ISQLQueryObject sqlQueryObjectGet = sqlQueryObject.newSQLQueryObject();

  643.         // Object _soggettoRuolo
  644.         sqlQueryObjectGet.addFromTable(this.getSoggettoRuoloFieldConverter().toTable(SoggettoRuolo.model()));
  645.         sqlQueryObjectGet.addSelectField("id_soggetto");
  646.         sqlQueryObjectGet.addSelectField("id_ruolo");
  647.         sqlQueryObjectGet.setANDLogicOperator(true);
  648.         sqlQueryObjectGet.addWhereCondition("id=?");

  649.         // Recupero _soggettoRuolo
  650.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject [] searchParams_soggettoRuolo = new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject [] {
  651.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(tableId,Long.class)
  652.         };
  653.         List<Class<?>> listaFieldIdReturnType_soggettoRuolo = new ArrayList<Class<?>>();
  654.         listaFieldIdReturnType_soggettoRuolo.add(Long.class);
  655.         listaFieldIdReturnType_soggettoRuolo.add(Long.class);
  656.         org.openspcoop2.core.commons.search.IdSoggettoRuolo id_soggettoRuolo = null;
  657.         List<Object> listaFieldId_soggettoRuolo = jdbcUtilities.executeQuerySingleResult(sqlQueryObjectGet.createSQLQuery(), jdbcProperties.isShowSql(),
  658.                 listaFieldIdReturnType_soggettoRuolo, searchParams_soggettoRuolo);
  659.         if(listaFieldId_soggettoRuolo==null || listaFieldId_soggettoRuolo.size()<=0){
  660.             if(throwNotFound){
  661.                 throw org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.newNotFoundException();
  662.             }
  663.         }
  664.         else{
  665.             // set _soggettoRuolo
  666.             id_soggettoRuolo = new org.openspcoop2.core.commons.search.IdSoggettoRuolo();
  667.            
  668.             IdSoggetto idSoggetto = new IdSoggetto();
  669.             idSoggetto.setId((Long) listaFieldId_soggettoRuolo.get(0));
  670.             Soggetto soggetto = ((IDBSoggettoServiceSearch)this.getServiceManager(connection, jdbcProperties, log).getSoggettoServiceSearch()).get(idSoggetto.getId());
  671.             idSoggetto.setTipo(soggetto.getTipoSoggetto());
  672.             idSoggetto.setNome(soggetto.getNomeSoggetto());
  673.             id_soggettoRuolo.setIdSoggetto(idSoggetto);
  674.            
  675.             IdRuolo idRuolo = new IdRuolo();
  676.             idRuolo.setId((Long) listaFieldId_soggettoRuolo.get(1));
  677.             Ruolo ruolo = ((IDBRuoloServiceSearch)this.getServiceManager(connection, jdbcProperties, log).getRuoloServiceSearch()).get(idRuolo.getId());
  678.             idRuolo.setNome(ruolo.getNome());
  679.             id_soggettoRuolo.setIdRuolo(idRuolo);
  680.            
  681.         }
  682.        
  683.         return id_soggettoRuolo;
  684.        
  685.     }

  686.     @Override
  687.     public Long findTableId(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdSoggettoRuolo id, boolean throwNotFound)
  688.             throws NotFoundException, ServiceException, NotImplementedException, Exception {
  689.    
  690.         return this.findIdSoggettoRuolo(jdbcProperties,log,connection,sqlQueryObject,id,throwNotFound);
  691.            
  692.     }
  693.    
  694.     @Override
  695.     public List<List<Object>> nativeQuery(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  696.                                             String sql,List<Class<?>> returnClassTypes,Object ... param) throws ServiceException,NotFoundException,NotImplementedException,Exception{
  697.        
  698.         return org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.nativeQuery(jdbcProperties, log, connection, sqlQueryObject,
  699.                                                                                             sql,returnClassTypes,param);
  700.                                                        
  701.     }
  702.    
  703.     protected Long findIdSoggettoRuolo(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdSoggettoRuolo id, boolean throwNotFound) throws NotFoundException, ServiceException, NotImplementedException, Exception {

  704.         if(jdbcProperties==null) {
  705.             throw new ServiceException("Param jdbcProperties is null");
  706.         }
  707.         if(sqlQueryObject==null) {
  708.             throw new ServiceException("Param sqlQueryObject is null");
  709.         }
  710.         if(id==null) {
  711.             throw new ServiceException("Param id is null");
  712.         }
  713.        
  714.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  715.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);

  716.         ISQLQueryObject sqlQueryObjectGet = sqlQueryObject.newSQLQueryObject();

  717.        
  718.         // Object _soggettoRuolo
  719.         sqlQueryObjectGet.addFromTable(this.getSoggettoRuoloFieldConverter().toTable(SoggettoRuolo.model()));
  720.         sqlQueryObjectGet.addSelectField("id");
  721.         // Devono essere mappati nella where condition i metodi dell'oggetto id.getXXX
  722.         sqlQueryObjectGet.setANDLogicOperator(true);
  723.         sqlQueryObjectGet.setSelectDistinct(true);
  724.         sqlQueryObjectGet.addWhereCondition("id_soggetto=?");
  725.         sqlQueryObjectGet.addWhereCondition("id_ruolo=?");

  726.         long idSoggetto = ((IDBSoggettoServiceSearch)this.getServiceManager(connection, jdbcProperties, log).getSoggettoServiceSearch()).findTableId(id.getIdSoggetto(), true);
  727.         long idRuolo = ((IDBRuoloServiceSearch)this.getServiceManager(connection, jdbcProperties, log).getRuoloServiceSearch()).findTableId(id.getIdRuolo(), true);
  728.        
  729.         // Recupero _soggettoRuolo
  730.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject [] searchParams_soggettoRuolo = new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject [] {
  731.                 new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(idSoggetto,long.class),
  732.                 new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(idRuolo,long.class)
  733.         };
  734.         Long id_soggettoRuolo = null;
  735.         try{
  736.             id_soggettoRuolo = (Long) jdbcUtilities.executeQuerySingleResult(sqlQueryObjectGet.createSQLQuery(), jdbcProperties.isShowSql(),
  737.                         Long.class, searchParams_soggettoRuolo);
  738.         }catch(NotFoundException notFound){
  739.             if(throwNotFound){
  740.                 throw new NotFoundException(notFound);
  741.             }
  742.         }
  743.         if(id_soggettoRuolo==null || id_soggettoRuolo<=0){
  744.             if(throwNotFound){
  745.                 throw org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.newNotFoundException();
  746.             }
  747.         }
  748.        
  749.         return id_soggettoRuolo;
  750.     }
  751. }