JDBCCredenzialeMittenteServiceSearchImpl.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.transazioni.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.transazioni.CredenzialeMittente;
  26. import org.openspcoop2.core.transazioni.IdCredenzialeMittente;
  27. import org.openspcoop2.core.transazioni.dao.jdbc.converter.CredenzialeMittenteFieldConverter;
  28. import org.openspcoop2.core.transazioni.dao.jdbc.fetch.CredenzialeMittenteFetch;
  29. import org.openspcoop2.generic_project.beans.CustomField;
  30. import org.openspcoop2.generic_project.beans.FunctionField;
  31. import org.openspcoop2.generic_project.beans.IField;
  32. import org.openspcoop2.generic_project.beans.InUse;
  33. import org.openspcoop2.generic_project.beans.NonNegativeNumber;
  34. import org.openspcoop2.generic_project.beans.Union;
  35. import org.openspcoop2.generic_project.beans.UnionExpression;
  36. import org.openspcoop2.generic_project.dao.jdbc.IJDBCServiceSearchWithId;
  37. import org.openspcoop2.generic_project.dao.jdbc.JDBCExpression;
  38. import org.openspcoop2.generic_project.dao.jdbc.JDBCPaginatedExpression;
  39. import org.openspcoop2.generic_project.dao.jdbc.JDBCServiceManagerProperties;
  40. import org.openspcoop2.generic_project.dao.jdbc.utils.IJDBCFetch;
  41. import org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject;
  42. import org.openspcoop2.generic_project.exception.MultipleResultException;
  43. import org.openspcoop2.generic_project.exception.NotFoundException;
  44. import org.openspcoop2.generic_project.exception.NotImplementedException;
  45. import org.openspcoop2.generic_project.exception.ServiceException;
  46. import org.openspcoop2.generic_project.expression.IExpression;
  47. import org.openspcoop2.generic_project.expression.impl.sql.ISQLFieldConverter;
  48. import org.openspcoop2.generic_project.utils.UtilsTemplate;
  49. import org.openspcoop2.utils.sql.ISQLQueryObject;
  50. import org.openspcoop2.utils.sql.SQLQueryObjectCore;
  51. import org.slf4j.Logger;

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

  60.     private CredenzialeMittenteFieldConverter _credenzialeMittenteFieldConverter = null;
  61.     public CredenzialeMittenteFieldConverter getCredenzialeMittenteFieldConverter() {
  62.         if(this._credenzialeMittenteFieldConverter==null){
  63.             this._credenzialeMittenteFieldConverter = new CredenzialeMittenteFieldConverter(this.jdbcServiceManager.getJdbcProperties().getDatabaseType());
  64.         }      
  65.         return this._credenzialeMittenteFieldConverter;
  66.     }
  67.     @Override
  68.     public ISQLFieldConverter getFieldConverter() {
  69.         return this.getCredenzialeMittenteFieldConverter();
  70.     }
  71.    
  72.     private CredenzialeMittenteFetch credenzialeMittenteFetch = new CredenzialeMittenteFetch();
  73.     public CredenzialeMittenteFetch getCredenzialeMittenteFetch() {
  74.         return this.credenzialeMittenteFetch;
  75.     }
  76.     @Override
  77.     public IJDBCFetch getFetch() {
  78.         return getCredenzialeMittenteFetch();
  79.     }
  80.    
  81.    
  82.     private JDBCServiceManager jdbcServiceManager = null;

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

  93.     @Override
  94.     public IdCredenzialeMittente convertToId(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, CredenzialeMittente credenzialeMittente) throws NotImplementedException, ServiceException, Exception{
  95.    
  96.         IdCredenzialeMittente idCredenzialeMittente = new IdCredenzialeMittente();
  97.         idCredenzialeMittente.setTipo(credenzialeMittente.getTipo());
  98.         idCredenzialeMittente.setCredenziale(credenzialeMittente.getCredenziale());
  99.         return idCredenzialeMittente;
  100.     }
  101.    
  102.     private static boolean efficiente = true;
  103.     public static boolean isEfficiente() {
  104.         return efficiente;
  105.     }
  106.     public static void setEfficiente(boolean efficiente) {
  107.         JDBCCredenzialeMittenteServiceSearchImpl.efficiente = efficiente;
  108.     }
  109.     @Override
  110.     public CredenzialeMittente get(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdCredenzialeMittente id, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotFoundException, MultipleResultException, NotImplementedException, ServiceException,Exception {
  111.        
  112.         long id_long = (id!=null && id.getId()!=null && id.getId()>0) ? id.getId() : -1;
  113.        
  114.         if(id_long<=0 && efficiente){
  115.        
  116.             if(id==null) {
  117.                 throw new ServiceException("Id undefined");
  118.             }
  119.             if(id.getTipo()==null) {
  120.                 throw new ServiceException("Id.tipo undefined");
  121.             }
  122.             if(id.getCredenziale()==null) {
  123.                 throw new ServiceException("Id.credenziale undefined");
  124.             }
  125.            
  126.             JDBCPaginatedExpression pagExpr = this.newPaginatedExpression(log);
  127.             pagExpr.equals(CredenzialeMittente.model().TIPO, id.getTipo());
  128.             pagExpr.and();
  129.             pagExpr.equals(CredenzialeMittente.model().CREDENZIALE, id.getCredenziale());
  130.             //pagExpr.limit(2); Inefficiente, per implementare il multipleresult che poi non può succedere
  131.             pagExpr.limit(1);
  132.            
  133.             List<CredenzialeMittente> list = findAll(jdbcProperties, log, connection, sqlQueryObject, pagExpr, idMappingResolutionBehaviour);
  134.            
  135.             if(list==null || list.size()<1) {
  136.                 throw new NotFoundException();
  137.             }
  138.             // C'è lo unique sulle due colonne
  139. //          else if(list.size()>1) {
  140. //              throw new MultipleResultException();
  141. //          }
  142.             else {
  143.                 return list.get(0);
  144.             }
  145.            
  146.         }
  147.         else {
  148.             Long id_credenzialeMittente = ( (id!=null && id.getId()!=null && id.getId()>0) ? id.getId() : this.findIdCredenzialeMittente(jdbcProperties, log, connection, sqlQueryObject, id, true));
  149.             return this.getEngine(jdbcProperties, log, connection, sqlQueryObject, id_credenzialeMittente,idMappingResolutionBehaviour);
  150.         }
  151.        
  152.     }
  153.    
  154.     @Override
  155.     public boolean exists(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdCredenzialeMittente id) throws MultipleResultException, NotImplementedException, ServiceException,Exception {

  156.         Long id_credenzialeMittente = this.findIdCredenzialeMittente(jdbcProperties, log, connection, sqlQueryObject, id, false);
  157.         return id_credenzialeMittente != null && id_credenzialeMittente > 0;
  158.        
  159.     }
  160.    
  161.     @Override
  162.     public List<IdCredenzialeMittente> findAllIds(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCPaginatedExpression expression, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotImplementedException, ServiceException,Exception {

  163.         List<IdCredenzialeMittente> list = new ArrayList<IdCredenzialeMittente>();

  164.         if(efficiente) {
  165.        
  166.             List<IField> fields = new ArrayList<IField>();
  167.             fields.add(CredenzialeMittente.model().TIPO);
  168.             fields.add(CredenzialeMittente.model().CREDENZIALE);
  169.             fields.add(CredenzialeMittente.model().ORA_REGISTRAZIONE);
  170.             fields.add(CredenzialeMittente.model().REF_CREDENZIALE);
  171.             fields.add(new CustomField("id", Long.class, "id", this.getCredenzialeMittenteFieldConverter().toTable(CredenzialeMittente.model())));
  172.            
  173.             List<Map<String, Object>> returnMap = null;
  174.             try{
  175.                  // Il distinct serve solo se ci sono le ricerche con contenuto.
  176.                 // NOTA: il distinct rende le ricerce inefficienti (ed inoltre non e' utilizzabile con campi clob in oracle)
  177.                 boolean distinct = false;
  178.                 ISQLQueryObject sqlQueryObjectCheckJoin = sqlQueryObject.newSQLQueryObject();
  179.                 joinEngine(expression, sqlQueryObjectCheckJoin);
  180.                 distinct = ((SQLQueryObjectCore)sqlQueryObjectCheckJoin).sizeConditions()>0;
  181.                
  182.                 // BUG FIX: Siccome tra le colonne lette ci sono dei CLOB, in oracle non e' consentito utilizzare il DISTINCT.
  183.                 // Per questo motivo se c'e' da usare il distinct viene utilizzato il vecchio metodo
  184.                 if(distinct) {
  185.                     //System.out.println("NON EFFICIENTE");
  186.                    
  187.                     List<Long> ids = this.findAllTableIds(jdbcProperties, log, connection, sqlQueryObject, expression);
  188.                    
  189.                     for(Long id: ids) {
  190.                         CredenzialeMittente credenzialeMittente = this.get(jdbcProperties, log, connection, sqlQueryObject, id, idMappingResolutionBehaviour);
  191.                         IdCredenzialeMittente idCredenzialeMittente = this.convertToId(jdbcProperties,log,connection,sqlQueryObject,credenzialeMittente);
  192.                         list.add(idCredenzialeMittente);
  193.                     }
  194.                    
  195.                 }
  196.                 else {
  197.                
  198.                     //System.out.println("EFFICIENTE");
  199.                    
  200.                     returnMap = this.select(jdbcProperties, log, connection, sqlQueryObject, expression, distinct, fields.toArray(new IField[1]));
  201.        
  202.                     for(Map<String, Object> map: returnMap) {
  203.                         CredenzialeMittente credenzialeMittente = (CredenzialeMittente)this.getCredenzialeMittenteFetch().fetch(jdbcProperties.getDatabase(), CredenzialeMittente.model(), map);
  204.                         IdCredenzialeMittente idCredenzialeMittente = this.convertToId(jdbcProperties,log,connection,sqlQueryObject,credenzialeMittente);
  205.                         list.add(idCredenzialeMittente);
  206.                     }
  207.                    
  208.                 }
  209.                    
  210.             }catch(NotFoundException notFound){}
  211.            
  212.         }
  213.         else {
  214.        
  215.             // TODO: implementazione non efficiente.
  216.             // Per ottenere una implementazione efficiente:
  217.             // 1. Usare metodo select di questa classe indirizzando esattamente i field necessari a create l'ID logico
  218.             // 2. Usare metodo getCredenzialeMittenteFetch() sul risultato della select per ottenere un oggetto CredenzialeMittente
  219.             //    La fetch con la map inserirà nell'oggetto solo i valori estratti
  220.             // 3. Usare metodo convertToId per ottenere l'id
  221.    
  222.             List<Long> ids = this.findAllTableIds(jdbcProperties, log, connection, sqlQueryObject, expression);
  223.            
  224.             for(Long id: ids) {
  225.                 CredenzialeMittente credenzialeMittente = this.get(jdbcProperties, log, connection, sqlQueryObject, id, idMappingResolutionBehaviour);
  226.                 IdCredenzialeMittente idCredenzialeMittente = this.convertToId(jdbcProperties,log,connection,sqlQueryObject,credenzialeMittente);
  227.                 list.add(idCredenzialeMittente);
  228.             }
  229.            
  230.         }

  231.         return list;
  232.        
  233.     }
  234.    
  235.     @Override
  236.     public List<CredenzialeMittente> findAll(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCPaginatedExpression expression, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotImplementedException, ServiceException,Exception {

  237.         List<CredenzialeMittente> list = new ArrayList<CredenzialeMittente>();
  238.        
  239.         if(efficiente) {
  240.        
  241.             List<IField> fields = new ArrayList<IField>();
  242.             fields.add(CredenzialeMittente.model().TIPO);
  243.             fields.add(CredenzialeMittente.model().CREDENZIALE);
  244.             fields.add(CredenzialeMittente.model().ORA_REGISTRAZIONE);
  245.             fields.add(CredenzialeMittente.model().REF_CREDENZIALE);
  246.             fields.add(new CustomField("id", Long.class, "id", this.getCredenzialeMittenteFieldConverter().toTable(CredenzialeMittente.model())));
  247.            
  248.             List<Map<String, Object>> returnMap = null;
  249.             try{
  250.                  // Il distinct serve solo se ci sono le ricerche con contenuto.
  251.                 // NOTA: il distinct rende le ricerce inefficienti (ed inoltre non e' utilizzabile con campi clob in oracle)
  252.                 boolean distinct = false;
  253.                 ISQLQueryObject sqlQueryObjectCheckJoin = sqlQueryObject.newSQLQueryObject();
  254.                 joinEngine(expression, sqlQueryObjectCheckJoin);
  255.                 distinct = ((SQLQueryObjectCore)sqlQueryObjectCheckJoin).sizeConditions()>0;
  256.                
  257.                 // BUG FIX: Siccome tra le colonne lette ci sono dei CLOB, in oracle non e' consentito utilizzare il DISTINCT.
  258.                 // Per questo motivo se c'e' da usare il distinct viene utilizzato il vecchio metodo
  259.                 if(distinct) {
  260.                     //System.out.println("NON EFFICIENTE");
  261.                    
  262.                     List<Long> ids = this.findAllTableIds(jdbcProperties, log, connection, sqlQueryObject, expression);
  263.                    
  264.                     for(Long id: ids) {
  265.                         list.add(this.get(jdbcProperties, log, connection, sqlQueryObject, id, idMappingResolutionBehaviour));
  266.                     }
  267.                    
  268.                 }
  269.                 else {
  270.                
  271.                     //System.out.println("EFFICIENTE");
  272.                    
  273.                     returnMap = this.select(jdbcProperties, log, connection, sqlQueryObject, expression, distinct, fields.toArray(new IField[1]));
  274.        
  275.                     for(Map<String, Object> map: returnMap) {
  276.                         list.add((CredenzialeMittente)this.getCredenzialeMittenteFetch().fetch(jdbcProperties.getDatabase(), CredenzialeMittente.model(), map));
  277.                     }
  278.                    
  279.                 }
  280.                    
  281.             }catch(NotFoundException notFound){}
  282.            
  283.         }
  284.         else {
  285.             // TODO: implementazione non efficiente.
  286.             // Per ottenere una implementazione efficiente:
  287.             // 1. Usare metodo select di questa classe indirizzando esattamente i field necessari
  288.             // 2. Usare metodo getCredenzialeMittenteFetch() sul risultato della select per ottenere un oggetto CredenzialeMittente
  289.             //    La fetch con la map inserirà nell'oggetto solo i valori estratti
  290.    
  291.             List<Long> ids = this.findAllTableIds(jdbcProperties, log, connection, sqlQueryObject, expression);
  292.            
  293.             for(Long id: ids) {
  294.                 list.add(this.get(jdbcProperties, log, connection, sqlQueryObject, id, idMappingResolutionBehaviour));
  295.             }
  296.         }

  297.         return list;      
  298.        
  299.     }
  300.    
  301.     @Override
  302.     public CredenzialeMittente find(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCExpression expression, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour)
  303.         throws NotFoundException, MultipleResultException, NotImplementedException, ServiceException,Exception {

  304.         if(efficiente) {
  305.             JDBCPaginatedExpression pagExpr = this.toPaginatedExpression(expression, log);
  306.             pagExpr.limit(2);// dovrebbe esisterne uno solo
  307.             List<CredenzialeMittente>  list = this.findAll(jdbcProperties, log, connection, sqlQueryObject, pagExpr, idMappingResolutionBehaviour);
  308.             if(list==null || list.isEmpty()) {
  309.                 throw new NotFoundException("Ricerca non ha trovato entries");
  310.             }
  311.             else if(list.size()>1) {
  312.                 throw new NotFoundException("Ricerca ha trovato più entries");
  313.             }
  314.             else {
  315.                 return list.get(0);
  316.             }
  317.         }
  318.         else {
  319.        
  320.             long id = this.findTableId(jdbcProperties, log, connection, sqlQueryObject, expression);
  321.             if(id>0){
  322.                 return this.get(jdbcProperties, log, connection, sqlQueryObject, id, idMappingResolutionBehaviour);
  323.             }else{
  324.                 throw new NotFoundException("Entry with id["+id+"] not found");
  325.             }
  326.         }
  327.        
  328.     }
  329.    
  330.     @Override
  331.     public NonNegativeNumber count(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCExpression expression) throws NotImplementedException, ServiceException,Exception {
  332.        
  333.         List<Object> listaQuery = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareCount(jdbcProperties, log, connection, sqlQueryObject, expression,
  334.                                                 this.getCredenzialeMittenteFieldConverter(), CredenzialeMittente.model());
  335.        
  336.         sqlQueryObject.addSelectCountField(this.getCredenzialeMittenteFieldConverter().toTable(CredenzialeMittente.model())+".id","tot",true);
  337.        
  338.         joinEngine(expression,sqlQueryObject);
  339.        
  340.         return org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.count(jdbcProperties, log, connection, sqlQueryObject, expression,
  341.                                                                             this.getCredenzialeMittenteFieldConverter(), CredenzialeMittente.model(),listaQuery);
  342.     }

  343.     @Override
  344.     public InUse inUse(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdCredenzialeMittente id) throws NotFoundException, NotImplementedException, ServiceException,Exception {
  345.        
  346.         Long id_credenzialeMittente = this.findIdCredenzialeMittente(jdbcProperties, log, connection, sqlQueryObject, id, true);
  347.         return this.inUseEngine(jdbcProperties, log, connection, sqlQueryObject, id_credenzialeMittente);
  348.        
  349.     }

  350.     @Override
  351.     public List<Object> select(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  352.                                                     JDBCPaginatedExpression paginatedExpression, IField field) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  353.         return this.select(jdbcProperties, log, connection, sqlQueryObject,
  354.                                 paginatedExpression, false, field);
  355.     }
  356.    
  357.     @Override
  358.     public List<Object> select(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  359.                                                     JDBCPaginatedExpression paginatedExpression, boolean distinct, IField field) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  360.         List<Map<String,Object>> map =
  361.             this.select(jdbcProperties, log, connection, sqlQueryObject, paginatedExpression, distinct, new IField[]{field});
  362.         return org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.selectSingleObject(map);
  363.     }
  364.    
  365.     @Override
  366.     public List<Map<String,Object>> select(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  367.                                                     JDBCPaginatedExpression paginatedExpression, IField ... field) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  368.         return this.select(jdbcProperties, log, connection, sqlQueryObject,
  369.                                 paginatedExpression, false, field);
  370.     }
  371.    
  372.     @Override
  373.     public List<Map<String,Object>> select(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  374.                                                     JDBCPaginatedExpression paginatedExpression, boolean distinct, IField ... field) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  375.        
  376.         org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.setFields(sqlQueryObject,paginatedExpression,field);
  377.         try{
  378.        
  379.             ISQLQueryObject sqlQueryObjectDistinct =
  380.                         org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareSqlQueryObjectForSelectDistinct(distinct,sqlQueryObject, paginatedExpression, log,
  381.                                                 this.getCredenzialeMittenteFieldConverter(), field);

  382.             return selectEngine(jdbcProperties, log, connection, sqlQueryObject, paginatedExpression, sqlQueryObjectDistinct);
  383.            
  384.         }finally{
  385.             org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.removeFields(sqlQueryObject,paginatedExpression,field);
  386.         }
  387.     }

  388.     @Override
  389.     public Object aggregate(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  390.                                                     JDBCExpression expression, FunctionField functionField) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  391.         Map<String,Object> map =
  392.             this.aggregate(jdbcProperties, log, connection, sqlQueryObject, expression, new FunctionField[]{functionField});
  393.         return org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.selectAggregateObject(map,functionField);
  394.     }
  395.    
  396.     @Override
  397.     public Map<String,Object> aggregate(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  398.                                                     JDBCExpression expression, FunctionField ... functionField) throws ServiceException,NotFoundException,NotImplementedException,Exception {                                                  
  399.        
  400.         org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.setFields(sqlQueryObject,expression,functionField);
  401.         try{
  402.             List<Map<String,Object>> list = selectEngine(jdbcProperties, log, connection, sqlQueryObject, expression);
  403.             return list.get(0);
  404.         }finally{
  405.             org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.removeFields(sqlQueryObject,expression,functionField);
  406.         }
  407.     }

  408.     @Override
  409.     public List<Map<String,Object>> groupBy(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  410.                                                     JDBCExpression expression, FunctionField ... functionField) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  411.        
  412.         if(expression.getGroupByFields().isEmpty()){
  413.             throw new ServiceException("GroupBy conditions not found in expression");
  414.         }
  415.        
  416.         org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.setFields(sqlQueryObject,expression,functionField);
  417.         try{
  418.             return selectEngine(jdbcProperties, log, connection, sqlQueryObject, expression);
  419.         }finally{
  420.             org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.removeFields(sqlQueryObject,expression,functionField);
  421.         }
  422.     }
  423.    

  424.     @Override
  425.     public List<Map<String,Object>> groupBy(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  426.                                                     JDBCPaginatedExpression paginatedExpression, FunctionField ... functionField) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  427.        
  428.         if(paginatedExpression.getGroupByFields().isEmpty()){
  429.             throw new ServiceException("GroupBy conditions not found in expression");
  430.         }
  431.        
  432.         org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.setFields(sqlQueryObject,paginatedExpression,functionField);
  433.         try{
  434.             return selectEngine(jdbcProperties, log, connection, sqlQueryObject, paginatedExpression);
  435.         }finally{
  436.             org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.removeFields(sqlQueryObject,paginatedExpression,functionField);
  437.         }
  438.     }
  439.    
  440.     protected List<Map<String,Object>> selectEngine(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  441.                                                 IExpression expression) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  442.         return selectEngine(jdbcProperties, log, connection, sqlQueryObject, expression, null);
  443.     }
  444.     protected List<Map<String,Object>> selectEngine(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  445.                                                 IExpression expression, ISQLQueryObject sqlQueryObjectDistinct) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  446.        
  447.         List<Object> listaQuery = new ArrayList<>();
  448.         List<JDBCObject> listaParams = new ArrayList<>();
  449.         List<Object> returnField = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareSelect(jdbcProperties, log, connection, sqlQueryObject,
  450.                                 expression, this.getCredenzialeMittenteFieldConverter(), CredenzialeMittente.model(),
  451.                                 listaQuery,listaParams);
  452.        
  453.         joinEngine(expression,sqlQueryObject);
  454.        
  455.         List<Map<String,Object>> list = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.select(jdbcProperties, log, connection,
  456.                                         org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareSqlQueryObjectForSelectDistinct(sqlQueryObject,sqlQueryObjectDistinct),
  457.                                         expression, this.getCredenzialeMittenteFieldConverter(), CredenzialeMittente.model(),
  458.                                         listaQuery,listaParams,returnField);
  459.         if(list!=null && !list.isEmpty()){
  460.             return list;
  461.         }
  462.         else{
  463.             throw org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.newNotFoundException();
  464.         }
  465.     }
  466.    
  467.     @Override
  468.     public List<Map<String,Object>> union(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  469.                                                 Union union, UnionExpression ... unionExpression) throws ServiceException,NotFoundException,NotImplementedException,Exception {    
  470.        
  471.         List<ISQLQueryObject> sqlQueryObjectInnerList = new ArrayList<>();
  472.         List<JDBCObject> jdbcObjects = new ArrayList<>();
  473.         List<Class<?>> returnClassTypes = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareUnion(jdbcProperties, log, connection, sqlQueryObject,
  474.                                 this.getCredenzialeMittenteFieldConverter(), CredenzialeMittente.model(),
  475.                                 sqlQueryObjectInnerList, jdbcObjects, union, unionExpression);
  476.        
  477.         if(unionExpression!=null){
  478.             for (int i = 0; i < unionExpression.length; i++) {
  479.                 UnionExpression ue = unionExpression[i];
  480.                 IExpression expression = ue.getExpression();
  481.                 joinEngine(expression,sqlQueryObjectInnerList.get(i));
  482.             }
  483.         }
  484.        
  485.         List<Map<String,Object>> list = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.union(jdbcProperties, log, connection, sqlQueryObject,
  486.                                         this.getCredenzialeMittenteFieldConverter(), CredenzialeMittente.model(),
  487.                                         sqlQueryObjectInnerList, jdbcObjects, returnClassTypes, union, unionExpression);
  488.         if(list!=null && !list.isEmpty()){
  489.             return list;
  490.         }
  491.         else{
  492.             throw org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.newNotFoundException();
  493.         }                              
  494.     }
  495.    
  496.     @Override
  497.     public NonNegativeNumber unionCount(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  498.                                                 Union union, UnionExpression ... unionExpression) throws ServiceException,NotFoundException,NotImplementedException,Exception {    
  499.        
  500.         List<ISQLQueryObject> sqlQueryObjectInnerList = new ArrayList<>();
  501.         List<JDBCObject> jdbcObjects = new ArrayList<>();
  502.         List<Class<?>> returnClassTypes = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareUnionCount(jdbcProperties, log, connection, sqlQueryObject,
  503.                                 this.getCredenzialeMittenteFieldConverter(), CredenzialeMittente.model(),
  504.                                 sqlQueryObjectInnerList, jdbcObjects, union, unionExpression);
  505.        
  506.         if(unionExpression!=null){
  507.             for (int i = 0; i < unionExpression.length; i++) {
  508.                 UnionExpression ue = unionExpression[i];
  509.                 IExpression expression = ue.getExpression();
  510.                 joinEngine(expression,sqlQueryObjectInnerList.get(i));
  511.             }
  512.         }
  513.        
  514.         NonNegativeNumber number = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.unionCount(jdbcProperties, log, connection, sqlQueryObject,
  515.                                         this.getCredenzialeMittenteFieldConverter(), CredenzialeMittente.model(),
  516.                                         sqlQueryObjectInnerList, jdbcObjects, returnClassTypes, union, unionExpression);
  517.         if(number!=null && number.longValue()>=0){
  518.             return number;
  519.         }
  520.         else{
  521.             throw org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.newNotFoundException();
  522.         }
  523.     }



  524.     // -- ConstructorExpression

  525.     @Override
  526.     public JDBCExpression newExpression(Logger log) throws NotImplementedException, ServiceException {
  527.         try{
  528.             return new JDBCExpression(this.getCredenzialeMittenteFieldConverter());
  529.         }catch(Exception e){
  530.             throw new ServiceException(e);
  531.         }
  532.     }


  533.     @Override
  534.     public JDBCPaginatedExpression newPaginatedExpression(Logger log) throws NotImplementedException, ServiceException {
  535.         try{
  536.             return new JDBCPaginatedExpression(this.getCredenzialeMittenteFieldConverter());
  537.         }catch(Exception e){
  538.             throw new ServiceException(e);
  539.         }
  540.     }
  541.    
  542.     @Override
  543.     public JDBCExpression toExpression(JDBCPaginatedExpression paginatedExpression, Logger log) throws NotImplementedException, ServiceException {
  544.         try{
  545.             return new JDBCExpression(paginatedExpression);
  546.         }catch(Exception e){
  547.             throw new ServiceException(e);
  548.         }
  549.     }

  550.     @Override
  551.     public JDBCPaginatedExpression toPaginatedExpression(JDBCExpression expression, Logger log) throws NotImplementedException, ServiceException {
  552.         try{
  553.             return new JDBCPaginatedExpression(expression);
  554.         }catch(Exception e){
  555.             throw new ServiceException(e);
  556.         }
  557.     }
  558.    
  559.    
  560.    
  561.     // -- DB

  562.     @Override
  563.     public void mappingTableIds(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdCredenzialeMittente id, CredenzialeMittente obj) throws NotFoundException,NotImplementedException,ServiceException,Exception{
  564.         _mappingTableIds(jdbcProperties,log,connection,sqlQueryObject,obj,
  565.                 this.get(jdbcProperties,log,connection,sqlQueryObject,id,null));
  566.     }
  567.    
  568.     @Override
  569.     public void mappingTableIds(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId, CredenzialeMittente obj) throws NotFoundException,NotImplementedException,ServiceException,Exception{
  570.         _mappingTableIds(jdbcProperties,log,connection,sqlQueryObject,obj,
  571.                 this.get(jdbcProperties,log,connection,sqlQueryObject,tableId,null));
  572.     }
  573.     private void _mappingTableIds(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, CredenzialeMittente obj, CredenzialeMittente imgSaved) throws NotFoundException,NotImplementedException,ServiceException,Exception{
  574.         if(imgSaved==null){
  575.             return;
  576.         }
  577.         obj.setId(imgSaved.getId());

  578.     }
  579.    
  580.     @Override
  581.     public CredenzialeMittente get(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotFoundException, MultipleResultException, NotImplementedException, ServiceException, Exception {
  582.         return this.getEngine(jdbcProperties, log, connection, sqlQueryObject, Long.valueOf(tableId), idMappingResolutionBehaviour);
  583.     }
  584.    
  585.     private CredenzialeMittente getEngine(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, Long tableId, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotFoundException, MultipleResultException, NotImplementedException, ServiceException, Exception {
  586.    
  587.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  588.                     new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);
  589.        
  590.         ISQLQueryObject sqlQueryObjectGet = sqlQueryObject.newSQLQueryObject();
  591.                
  592.         CredenzialeMittente credenzialeMittente = new CredenzialeMittente();
  593.        

  594.         // Object credenzialeMittente
  595.         ISQLQueryObject sqlQueryObjectGet_credenzialeMittente = sqlQueryObjectGet.newSQLQueryObject();
  596.         sqlQueryObjectGet_credenzialeMittente.setANDLogicOperator(true);
  597.         sqlQueryObjectGet_credenzialeMittente.addFromTable(this.getCredenzialeMittenteFieldConverter().toTable(CredenzialeMittente.model()));
  598.         sqlQueryObjectGet_credenzialeMittente.addSelectField("id");
  599.         sqlQueryObjectGet_credenzialeMittente.addSelectField(this.getCredenzialeMittenteFieldConverter().toColumn(CredenzialeMittente.model().TIPO,true));
  600.         sqlQueryObjectGet_credenzialeMittente.addSelectField(this.getCredenzialeMittenteFieldConverter().toColumn(CredenzialeMittente.model().CREDENZIALE,true));
  601.         sqlQueryObjectGet_credenzialeMittente.addSelectField(this.getCredenzialeMittenteFieldConverter().toColumn(CredenzialeMittente.model().ORA_REGISTRAZIONE,true));
  602.         sqlQueryObjectGet_credenzialeMittente.addSelectField(this.getCredenzialeMittenteFieldConverter().toColumn(CredenzialeMittente.model().REF_CREDENZIALE,true));
  603.         sqlQueryObjectGet_credenzialeMittente.addWhereCondition("id=?");

  604.         // Get credenzialeMittente
  605.         credenzialeMittente = (CredenzialeMittente) jdbcUtilities.executeQuerySingleResult(sqlQueryObjectGet_credenzialeMittente.createSQLQuery(), jdbcProperties.isShowSql(), CredenzialeMittente.model(), this.getCredenzialeMittenteFetch(),
  606.             new JDBCObject(tableId,Long.class));



  607.        
  608.         return credenzialeMittente;  
  609.    
  610.     }
  611.    
  612.     @Override
  613.     public boolean exists(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId) throws MultipleResultException, NotImplementedException, ServiceException, Exception {
  614.         return this._exists(jdbcProperties, log, connection, sqlQueryObject, Long.valueOf(tableId));
  615.     }
  616.    
  617.     private boolean _exists(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, Long tableId) throws MultipleResultException, NotImplementedException, ServiceException, Exception {
  618.    
  619.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  620.                     new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);
  621.                
  622.         boolean existsCredenzialeMittente = false;

  623.         sqlQueryObject = sqlQueryObject.newSQLQueryObject();
  624.         sqlQueryObject.setANDLogicOperator(true);

  625.         sqlQueryObject.addFromTable(this.getCredenzialeMittenteFieldConverter().toTable(CredenzialeMittente.model()));
  626.         sqlQueryObject.addSelectField(this.getCredenzialeMittenteFieldConverter().toColumn(CredenzialeMittente.model().TIPO,true));
  627.         sqlQueryObject.addWhereCondition("id=?");


  628.         // Exists credenzialeMittente
  629.         existsCredenzialeMittente = jdbcUtilities.exists(sqlQueryObject.createSQLQuery(), jdbcProperties.isShowSql(),
  630.             new JDBCObject(tableId,Long.class));

  631.        
  632.         return existsCredenzialeMittente;
  633.    
  634.     }
  635.    
  636.     private void joinEngine(IExpression expression, ISQLQueryObject sqlQueryObject) throws NotImplementedException, ServiceException, Exception{
  637.    
  638.        
  639.     }
  640.    
  641.     protected java.util.List<Object> getRootTablePrimaryKeyValuesEngine(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdCredenzialeMittente id) throws NotFoundException, ServiceException, NotImplementedException, Exception{
  642.         // Identificativi
  643.         java.util.List<Object> rootTableIdValues = new java.util.ArrayList<>();
  644.         Long longId = this.findIdCredenzialeMittente(jdbcProperties, log, connection, sqlQueryObject.newSQLQueryObject(), id, true);
  645.         rootTableIdValues.add(longId);        
  646.         return rootTableIdValues;
  647.     }
  648.    
  649.     protected Map<String, List<IField>> getMapTableToPKColumnEngine() throws NotImplementedException, Exception{
  650.    
  651.         CredenzialeMittenteFieldConverter converter = this.getCredenzialeMittenteFieldConverter();
  652.         Map<String, List<IField>> mapTableToPKColumn = new java.util.HashMap<>();
  653.         UtilsTemplate<IField> utilities = new UtilsTemplate<>();

  654.         // CredenzialeMittente.model()
  655.         mapTableToPKColumn.put(converter.toTable(CredenzialeMittente.model()),
  656.             utilities.newList(
  657.                 new CustomField("id", Long.class, "id", converter.toTable(CredenzialeMittente.model()))
  658.             ));
  659.        
  660.         return mapTableToPKColumn;      
  661.     }
  662.    
  663.     @Override
  664.     public List<Long> findAllTableIds(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCPaginatedExpression paginatedExpression) throws ServiceException, NotImplementedException, Exception {
  665.        
  666.         List<Long> list = new ArrayList<Long>();

  667.         sqlQueryObject.setSelectDistinct(true);
  668.         sqlQueryObject.setANDLogicOperator(true);
  669.         sqlQueryObject.addSelectField(this.getCredenzialeMittenteFieldConverter().toTable(CredenzialeMittente.model())+".id");
  670.         Class<?> objectIdClass = Long.class;
  671.        
  672.         List<Object> listaQuery = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareFindAll(jdbcProperties, log, connection, sqlQueryObject, paginatedExpression,
  673.                                                 this.getCredenzialeMittenteFieldConverter(), CredenzialeMittente.model());
  674.        
  675.         joinEngine(paginatedExpression,sqlQueryObject);
  676.        
  677.         List<Object> listObjects = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.findAll(jdbcProperties, log, connection, sqlQueryObject, paginatedExpression,
  678.                                                                             this.getCredenzialeMittenteFieldConverter(), CredenzialeMittente.model(), objectIdClass, listaQuery);
  679.         for(Object object: listObjects) {
  680.             list.add((Long)object);
  681.         }

  682.         return list;
  683.        
  684.     }
  685.    
  686.     @Override
  687.     public long findTableId(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCExpression expression) throws ServiceException, NotFoundException, MultipleResultException, NotImplementedException, Exception {
  688.    
  689.         sqlQueryObject.setSelectDistinct(true);
  690.         sqlQueryObject.setANDLogicOperator(true);
  691.         sqlQueryObject.addSelectField(this.getCredenzialeMittenteFieldConverter().toTable(CredenzialeMittente.model())+".id");
  692.         Class<?> objectIdClass = Long.class;
  693.        
  694.         List<Object> listaQuery = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareFind(jdbcProperties, log, connection, sqlQueryObject, expression,
  695.                                                 this.getCredenzialeMittenteFieldConverter(), CredenzialeMittente.model());
  696.        
  697.         joinEngine(expression,sqlQueryObject);

  698.         Object res = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.find(jdbcProperties, log, connection, sqlQueryObject, expression,
  699.                                                         this.getCredenzialeMittenteFieldConverter(), CredenzialeMittente.model(), objectIdClass, listaQuery);
  700.         if(res!=null && (((Long) res).longValue()>0) ){
  701.             return ((Long) res).longValue();
  702.         }
  703.         else{
  704.             throw org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.newNotFoundException();
  705.         }
  706.        
  707.     }

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

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

  713.         InUse inUse = new InUse();
  714.         inUse.setInUse(false);
  715.        
  716.         /*
  717.          * TODO: implement code that checks whether the object identified by the id parameter is used by other objects
  718.         */
  719.        
  720.         // Delete this line when you have implemented the method
  721.         int throwNotImplemented = 1;
  722.         if(throwNotImplemented==1){
  723.                 throw new NotImplementedException("NotImplemented");
  724.         }
  725.         // Delete this line when you have implemented the method

  726.         return inUse;

  727.     }
  728.    
  729.     @Override
  730.     public IdCredenzialeMittente findId(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId, boolean throwNotFound)
  731.             throws NotFoundException, ServiceException, NotImplementedException, Exception {
  732.        
  733.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  734.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);

  735.         ISQLQueryObject sqlQueryObjectGet = sqlQueryObject.newSQLQueryObject();

  736.         // Object _credenzialeMittente
  737.         sqlQueryObjectGet.addFromTable(this.getCredenzialeMittenteFieldConverter().toTable(CredenzialeMittente.model()));
  738.         sqlQueryObjectGet.addSelectField(this.getCredenzialeMittenteFieldConverter().toColumn(CredenzialeMittente.model().TIPO,true));
  739.         sqlQueryObjectGet.addSelectField(this.getCredenzialeMittenteFieldConverter().toColumn(CredenzialeMittente.model().CREDENZIALE,true));
  740.         sqlQueryObjectGet.setANDLogicOperator(true);
  741.         sqlQueryObjectGet.addWhereCondition("id=?");

  742.         // Recupero _credenzialeMittente
  743.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject [] searchParams_credenzialeMittente = new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject [] {
  744.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(tableId,Long.class)
  745.         };
  746.         List<Class<?>> listaFieldIdReturnType_credenzialeMittente = new ArrayList<Class<?>>();
  747.         listaFieldIdReturnType_credenzialeMittente.add(String.class);
  748.         listaFieldIdReturnType_credenzialeMittente.add(String.class);
  749.         org.openspcoop2.core.transazioni.IdCredenzialeMittente id_credenzialeMittente = null;
  750.         List<Object> listaFieldId_credenzialeMittente = jdbcUtilities.executeQuerySingleResult(sqlQueryObjectGet.createSQLQuery(), jdbcProperties.isShowSql(),
  751.                 listaFieldIdReturnType_credenzialeMittente, searchParams_credenzialeMittente);
  752.         if(listaFieldId_credenzialeMittente==null || listaFieldId_credenzialeMittente.size()<=0){
  753.             if(throwNotFound){
  754.                 throw org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.newNotFoundException();
  755.             }
  756.         }
  757.         else{
  758.             // set _credenzialeMittente
  759.             id_credenzialeMittente = new org.openspcoop2.core.transazioni.IdCredenzialeMittente();
  760.             id_credenzialeMittente.setTipo((String)listaFieldId_credenzialeMittente.get(0));
  761.             id_credenzialeMittente.setCredenziale((String)listaFieldId_credenzialeMittente.get(1));
  762.         }
  763.        
  764.         return id_credenzialeMittente;
  765.        
  766.     }

  767.     @Override
  768.     public Long findTableId(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdCredenzialeMittente id, boolean throwNotFound)
  769.             throws NotFoundException, ServiceException, NotImplementedException, Exception {
  770.    
  771.         return this.findIdCredenzialeMittente(jdbcProperties,log,connection,sqlQueryObject,id,throwNotFound);
  772.            
  773.     }
  774.    
  775.     @Override
  776.     public List<List<Object>> nativeQuery(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  777.                                             String sql,List<Class<?>> returnClassTypes,Object ... param) throws ServiceException,NotFoundException,NotImplementedException,Exception{
  778.        
  779.         return org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.nativeQuery(jdbcProperties, log, connection, sqlQueryObject,
  780.                                                                                             sql,returnClassTypes,param);
  781.                                                        
  782.     }
  783.    
  784.     protected Long findIdCredenzialeMittente(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdCredenzialeMittente id, boolean throwNotFound) throws NotFoundException, ServiceException, NotImplementedException, Exception {

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

  787.         if(id==null) {
  788.             throw new ServiceException("Id undefined");
  789.         }
  790.         if(id.getTipo()==null) {
  791.             throw new ServiceException("Id.tipo undefined");
  792.         }
  793.         if(id.getCredenziale()==null) {
  794.             throw new ServiceException("Id.credenziale undefined");
  795.         }
  796.        
  797.         ISQLQueryObject sqlQueryObjectGet = sqlQueryObject.newSQLQueryObject();

  798.         // Object _credenzialeMittente
  799.         sqlQueryObjectGet.addFromTable(this.getCredenzialeMittenteFieldConverter().toTable(CredenzialeMittente.model()));
  800.         sqlQueryObjectGet.addSelectField("id");
  801.         // Devono essere mappati nella where condition i metodi dell'oggetto id.getXXX
  802.         sqlQueryObjectGet.setANDLogicOperator(true);
  803.         sqlQueryObjectGet.setSelectDistinct(true);
  804.         sqlQueryObjectGet.addWhereCondition(this.getCredenzialeMittenteFieldConverter().toColumn(CredenzialeMittente.model().TIPO,true)+"=?");
  805.         sqlQueryObjectGet.addWhereCondition(this.getCredenzialeMittenteFieldConverter().toColumn(CredenzialeMittente.model().CREDENZIALE,true)+"=?");

  806.         // Recupero _credenzialeMittente
  807.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject [] searchParams_credenzialeMittente = new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject [] {
  808.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(id.getTipo(),String.class),
  809.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(id.getCredenziale(),String.class)
  810.         };
  811.         Long id_credenzialeMittente = null;
  812.         try{
  813.             id_credenzialeMittente = (Long) jdbcUtilities.executeQuerySingleResult(sqlQueryObjectGet.createSQLQuery(), jdbcProperties.isShowSql(),
  814.                         Long.class, searchParams_credenzialeMittente);
  815.         }catch(NotFoundException notFound){
  816.             if(throwNotFound){
  817.                 throw new NotFoundException(notFound);
  818.             }
  819.         }
  820.         if(id_credenzialeMittente==null || id_credenzialeMittente<=0){
  821.             if(throwNotFound){
  822.                 throw org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.newNotFoundException();
  823.             }
  824.         }
  825.        
  826.         return id_credenzialeMittente;
  827.     }
  828. }