JDBCOperationServiceSearchImpl.java

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

  21. import java.util.List;
  22. import java.util.ArrayList;
  23. import java.util.Map;

  24. import java.sql.Connection;

  25. import org.slf4j.Logger;

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

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

  48. import org.openspcoop2.generic_project.dao.jdbc.JDBCServiceManagerProperties;
  49. import org.openspcoop2.core.commons.search.dao.jdbc.converter.OperationFieldConverter;
  50. import org.openspcoop2.core.commons.search.dao.jdbc.fetch.OperationFetch;
  51. import org.openspcoop2.core.commons.search.dao.IDBPortTypeServiceSearch;
  52. import org.openspcoop2.core.commons.search.Operation;
  53. import org.openspcoop2.core.commons.search.PortType;

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

  62.     private OperationFieldConverter _operationFieldConverter = null;
  63.     public OperationFieldConverter getOperationFieldConverter() {
  64.         if(this._operationFieldConverter==null){
  65.             this._operationFieldConverter = new OperationFieldConverter(this.jdbcServiceManager.getJdbcProperties().getDatabaseType());
  66.         }      
  67.         return this._operationFieldConverter;
  68.     }
  69.     @Override
  70.     public ISQLFieldConverter getFieldConverter() {
  71.         return this.getOperationFieldConverter();
  72.     }
  73.    
  74.     private OperationFetch operationFetch = new OperationFetch();
  75.     public OperationFetch getOperationFetch() {
  76.         return this.operationFetch;
  77.     }
  78.     @Override
  79.     public IJDBCFetch getFetch() {
  80.         return getOperationFetch();
  81.     }
  82.    
  83.    
  84.     private JDBCServiceManager jdbcServiceManager = null;

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

  98.     @Override
  99.     public IdOperation convertToId(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, Operation operation) throws NotImplementedException, ServiceException, Exception{
  100.    
  101.         IdOperation idOperation = new IdOperation();
  102.         idOperation.setNome(operation.getNome());
  103.         idOperation.setIdPortType(operation.getIdPortType());
  104.         return idOperation;

  105.     }
  106.    
  107.     @Override
  108.     public Operation get(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdOperation id, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotFoundException, MultipleResultException, NotImplementedException, ServiceException,Exception {
  109.         Long id_operation = ( (id!=null && id.getId()!=null && id.getId()>0) ? id.getId() : this.findIdOperation(jdbcProperties, log, connection, sqlQueryObject, id, true));
  110.         return this.getEngine(jdbcProperties, log, connection, sqlQueryObject, id_operation,idMappingResolutionBehaviour);
  111.        
  112.        
  113.     }
  114.    
  115.     @Override
  116.     public boolean exists(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdOperation id) throws MultipleResultException, NotImplementedException, ServiceException,Exception {

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

  124.         List<IdOperation> list = new ArrayList<IdOperation>();

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

  131.         List<Long> ids = this.findAllTableIds(jdbcProperties, log, connection, sqlQueryObject, expression);
  132.        
  133.         for(Long id: ids) {
  134.             Operation operation = this.get(jdbcProperties, log, connection, sqlQueryObject, id, idMappingResolutionBehaviour);
  135.             IdOperation idOperation = this.convertToId(jdbcProperties,log,connection,sqlQueryObject,operation);
  136.             list.add(idOperation);
  137.         }

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

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

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

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

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

  185.     @Override
  186.     public InUse inUse(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdOperation id) throws NotFoundException, NotImplementedException, ServiceException,Exception {
  187.        
  188.         Long id_operation = this.findIdOperation(jdbcProperties, log, connection, sqlQueryObject, id, true);
  189.         return this.inUseEngine(jdbcProperties, log, connection, sqlQueryObject, id_operation);
  190.        
  191.     }

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

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

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

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

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



  366.     // -- ConstructorExpression

  367.     @Override
  368.     public JDBCExpression newExpression(Logger log) throws NotImplementedException, ServiceException {
  369.         try{
  370.             return new JDBCExpression(this.getOperationFieldConverter());
  371.         }catch(Exception e){
  372.             throw new ServiceException(e);
  373.         }
  374.     }


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

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

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

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

  448.         // Object operation
  449.         ISQLQueryObject sqlQueryObjectGet_operation = sqlQueryObjectGet.newSQLQueryObject();
  450.         sqlQueryObjectGet_operation.setANDLogicOperator(true);
  451.         sqlQueryObjectGet_operation.addFromTable(this.getOperationFieldConverter().toTable(Operation.model()));
  452.         sqlQueryObjectGet_operation.addSelectField("id");
  453.         sqlQueryObjectGet_operation.addSelectField(this.getOperationFieldConverter().toColumn(Operation.model().NOME,true));
  454.         sqlQueryObjectGet_operation.addWhereCondition("id=?");

  455.         // Get operation
  456.         operation = (Operation) jdbcUtilities.executeQuerySingleResult(sqlQueryObjectGet_operation.createSQLQuery(), jdbcProperties.isShowSql(), Operation.model(), this.getOperationFetch(),
  457.             new JDBCObject(tableId,Long.class));

  458.        
  459.         // Recupero idPortType
  460.         ISQLQueryObject sqlQueryObjectGet_accordoServizioParteComune_pt = sqlQueryObjectGet.newSQLQueryObject();
  461.         sqlQueryObjectGet_accordoServizioParteComune_pt.addFromTable(this.getOperationFieldConverter().toTable(Operation.model()));
  462.         sqlQueryObjectGet_accordoServizioParteComune_pt.addSelectField("id_port_type");
  463.         sqlQueryObjectGet_accordoServizioParteComune_pt.setANDLogicOperator(true);
  464.         sqlQueryObjectGet_accordoServizioParteComune_pt.addWhereCondition("id=?");
  465.        
  466.         // Recupero _accordoServizioParteComune_soggetto
  467.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject [] searchParams_accordoServizioParteComune_pt = new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject [] {
  468.                 new JDBCObject(operation.getId(), Long.class)
  469.         };
  470.         Long id_accordoServizioParteComune_pt =
  471.             (Long) jdbcUtilities.executeQuerySingleResult(sqlQueryObjectGet_accordoServizioParteComune_pt.createSQLQuery(), jdbcProperties.isShowSql(),
  472.             Long.class, searchParams_accordoServizioParteComune_pt);
  473.        
  474.         IDBPortTypeServiceSearch search = ((IDBPortTypeServiceSearch)this.getServiceManager(connection, jdbcProperties, log).getPortTypeServiceSearch());
  475.         PortType pt = search.get(id_accordoServizioParteComune_pt);
  476.         IdPortType idPt = search.convertToId(pt);
  477.         operation.setIdPortType(idPt);
  478.        
  479.         return operation;  
  480.    
  481.     }
  482.    
  483.     @Override
  484.     public boolean exists(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId) throws MultipleResultException, NotImplementedException, ServiceException, Exception {
  485.         return this._exists(jdbcProperties, log, connection, sqlQueryObject, Long.valueOf(tableId));
  486.     }
  487.    
  488.     private boolean _exists(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, Long tableId) throws MultipleResultException, NotImplementedException, ServiceException, Exception {
  489.    
  490.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  491.                     new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);
  492.                
  493.         boolean existsOperation = false;

  494.         sqlQueryObject = sqlQueryObject.newSQLQueryObject();
  495.         sqlQueryObject.setANDLogicOperator(true);

  496.         sqlQueryObject.addFromTable(this.getOperationFieldConverter().toTable(Operation.model()));
  497.         sqlQueryObject.addSelectField(this.getOperationFieldConverter().toColumn(Operation.model().NOME,true));
  498.         sqlQueryObject.addWhereCondition("id=?");


  499.         // Exists operation
  500.         existsOperation = jdbcUtilities.exists(sqlQueryObject.createSQLQuery(), jdbcProperties.isShowSql(),
  501.             new JDBCObject(tableId,Long.class));

  502.        
  503.         return existsOperation;
  504.    
  505.     }
  506.    
  507.     private void joinEngine(IExpression expression, ISQLQueryObject sqlQueryObject) throws NotImplementedException, ServiceException, Exception{
  508.    
  509.         if(expression.inUseModel(Operation.model().ID_PORT_TYPE,false)){
  510.             String tableName1 = this.getOperationFieldConverter().toTable(Operation.model());
  511.             String tableName2 = this.getOperationFieldConverter().toTable(Operation.model().ID_PORT_TYPE);
  512.             sqlQueryObject.addWhereCondition(tableName1+".id_port_type="+tableName2+".id");
  513.         }
  514.         if(expression.inUseModel(Operation.model().ID_PORT_TYPE.ID_ACCORDO_SERVIZIO_PARTE_COMUNE,false)){
  515.             String tableName1 = this.getOperationFieldConverter().toTable(Operation.model().ID_PORT_TYPE);
  516.             String tableName2 = this.getOperationFieldConverter().toTable(Operation.model().ID_PORT_TYPE.ID_ACCORDO_SERVIZIO_PARTE_COMUNE);
  517.             sqlQueryObject.addWhereCondition(tableName1+".id_accordo="+tableName2+".id");
  518.         }
  519.         if(expression.inUseModel(Operation.model().ID_PORT_TYPE.ID_ACCORDO_SERVIZIO_PARTE_COMUNE.ID_SOGGETTO,false)){
  520.             String tableName1 = this.getOperationFieldConverter().toTable(Operation.model().ID_PORT_TYPE.ID_ACCORDO_SERVIZIO_PARTE_COMUNE);
  521.             String tableName2 = this.getOperationFieldConverter().toTable(Operation.model().ID_PORT_TYPE.ID_ACCORDO_SERVIZIO_PARTE_COMUNE.ID_SOGGETTO);
  522.             sqlQueryObject.addWhereCondition(tableName1+".id_referente="+tableName2+".id");
  523.         }
  524.        
  525.         // Check FROM Table necessarie per le join di oggetti annidati dal secondo livello in poi dove pero' non viene poi utilizzato l'oggetto del livello precedente nella espressione
  526.         if(expression.inUseModel(Operation.model().ID_PORT_TYPE.ID_ACCORDO_SERVIZIO_PARTE_COMUNE,false)){
  527.             if(expression.inUseModel(Operation.model().ID_PORT_TYPE,false)==false){
  528.                 sqlQueryObject.addFromTable(this.getOperationFieldConverter().toTable(Operation.model().ID_PORT_TYPE));
  529.             }
  530.         }
  531.         if(expression.inUseModel(Operation.model().ID_PORT_TYPE.ID_ACCORDO_SERVIZIO_PARTE_COMUNE.ID_SOGGETTO,false)){
  532.             if(expression.inUseModel(Operation.model().ID_PORT_TYPE.ID_ACCORDO_SERVIZIO_PARTE_COMUNE,false)==false){
  533.                 sqlQueryObject.addFromTable(this.getOperationFieldConverter().toTable(Operation.model().ID_PORT_TYPE.ID_ACCORDO_SERVIZIO_PARTE_COMUNE));
  534.             }
  535.         }
  536.        
  537.     }
  538.    
  539.     protected java.util.List<Object> getRootTablePrimaryKeyValuesEngine(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdOperation id) throws NotFoundException, ServiceException, NotImplementedException, Exception{
  540.         // Identificativi
  541.         java.util.List<Object> rootTableIdValues = new java.util.ArrayList<>();
  542.         Long longId = this.findIdOperation(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.         OperationFieldConverter converter = this.getOperationFieldConverter();
  550.         Map<String, List<IField>> mapTableToPKColumn = new java.util.HashMap<>();
  551.         UtilsTemplate<IField> utilities = new UtilsTemplate<>();

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

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

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

  567.         // Operation.model().ID_PORT_TYPE.ID_ACCORDO_SERVIZIO_PARTE_COMUNE.ID_SOGGETTO
  568.         mapTableToPKColumn.put(converter.toTable(Operation.model().ID_PORT_TYPE.ID_ACCORDO_SERVIZIO_PARTE_COMUNE.ID_SOGGETTO),
  569.             utilities.newList(
  570.                 new CustomField("id", Long.class, "id", converter.toTable(Operation.model().ID_PORT_TYPE.ID_ACCORDO_SERVIZIO_PARTE_COMUNE.ID_SOGGETTO))
  571.             ));

  572.         return mapTableToPKColumn;      
  573.     }
  574.    
  575.     @Override
  576.     public List<Long> findAllTableIds(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCPaginatedExpression paginatedExpression) throws ServiceException, NotImplementedException, Exception {
  577.        
  578.         List<Long> list = new ArrayList<Long>();

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

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

  610.         Object res = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.find(jdbcProperties, log, connection, sqlQueryObject, expression,
  611.                                                         this.getOperationFieldConverter(), Operation.model(), objectIdClass, listaQuery);
  612.         if(res!=null && (((Long) res).longValue()>0) ){
  613.             return ((Long) res).longValue();
  614.         }
  615.         else{
  616.             throw org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.newNotFoundException();
  617.         }
  618.        
  619.     }

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

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

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

  638.         return inUse;

  639.     }
  640.    
  641.     @Override
  642.     public IdOperation findId(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId, boolean throwNotFound)
  643.             throws NotFoundException, ServiceException, NotImplementedException, Exception {
  644.        
  645.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  646.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);

  647.         ISQLQueryObject sqlQueryObjectGet = sqlQueryObject.newSQLQueryObject();              

  648.         // Object _operation
  649.         sqlQueryObjectGet.addFromTable(this.getOperationFieldConverter().toTable(Operation.model()));
  650.         sqlQueryObjectGet.addSelectField(this.getOperationFieldConverter().toColumn(Operation.model().NOME,true));
  651.         sqlQueryObjectGet.addSelectField("id_port_type");
  652.         sqlQueryObjectGet.setANDLogicOperator(true);
  653.         sqlQueryObjectGet.addWhereCondition("id=?");

  654.         // Recupero _operation
  655.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject [] searchParams_operation = new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject [] {
  656.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(tableId,Long.class)
  657.         };
  658.         List<Class<?>> listaFieldIdReturnType_operation = new ArrayList<Class<?>>();
  659.         listaFieldIdReturnType_operation.add(String.class);
  660.         listaFieldIdReturnType_operation.add(Long.class);
  661.         org.openspcoop2.core.commons.search.IdOperation id_operation = null;
  662.         List<Object> listaFieldId_operation = jdbcUtilities.executeQuerySingleResult(sqlQueryObjectGet.createSQLQuery(), jdbcProperties.isShowSql(),
  663.                 listaFieldIdReturnType_operation, searchParams_operation);
  664.         if(listaFieldId_operation==null || listaFieldId_operation.size()<=0){
  665.             if(throwNotFound){
  666.                 throw org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.newNotFoundException();
  667.             }
  668.         }
  669.         else{
  670.             // set _operation
  671.             id_operation = new org.openspcoop2.core.commons.search.IdOperation();
  672.             id_operation.setNome((String)listaFieldId_operation.get(0));
  673.            
  674.             Long idPortTypeFK = (Long) listaFieldId_operation.get(1);
  675.             id_operation.
  676.                 setIdPortType(((IDBPortTypeServiceSearch)this.getServiceManager(connection, jdbcProperties, log).
  677.                         getPortTypeServiceSearch()).findId(idPortTypeFK, true));
  678.         }
  679.        
  680.         return id_operation;
  681.        
  682.     }

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

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

  713.         ISQLQueryObject sqlQueryObjectGet = sqlQueryObject.newSQLQueryObject();

  714.         if(id.getIdPortType()==null){
  715.             throw new ServiceException("IdPortType non definito");
  716.         }
  717.         if(id.getIdPortType().getIdAccordoServizioParteComune()==null){
  718.             throw new ServiceException("IdPortType.getIdAccordoServizioParteComune non definito");
  719.         }
  720.         if(id.getIdPortType().getIdAccordoServizioParteComune().getIdSoggetto()==null){
  721.             throw new ServiceException("IdPortType.getIdAccordoServizioParteComune.getIdSoggetto non definito");
  722.         }
  723.        
  724.        
  725.         // Recupero idPortType
  726.         PortType pt = this.getServiceManager(connection, jdbcProperties, log).getPortTypeServiceSearch().get(id.getIdPortType());
  727.        
  728.        
  729.         // Object _operation
  730.         sqlQueryObjectGet.addFromTable(this.getOperationFieldConverter().toTable(Operation.model()));
  731.         sqlQueryObjectGet.addSelectField("id");
  732.         sqlQueryObjectGet.setANDLogicOperator(true);
  733.         sqlQueryObjectGet.setSelectDistinct(true);
  734.         sqlQueryObjectGet.addWhereCondition(this.getOperationFieldConverter().toColumn(Operation.model().NOME,true)+"=?");
  735.         sqlQueryObjectGet.addWhereCondition("id_port_type=?");

  736.         // Recupero _operation
  737.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject [] searchParams_operation = new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject [] {
  738.                 new JDBCObject(id.getNome(), String.class),
  739.                 new JDBCObject(pt.getId(), Long.class)
  740.         };
  741.         Long id_operation = null;
  742.         try{
  743.             id_operation = (Long) jdbcUtilities.executeQuerySingleResult(sqlQueryObjectGet.createSQLQuery(), jdbcProperties.isShowSql(),
  744.                         Long.class, searchParams_operation);
  745.         }catch(NotFoundException notFound){
  746.             if(throwNotFound){
  747.                 throw new NotFoundException(notFound);
  748.             }
  749.         }
  750.         if(id_operation==null || id_operation<=0){
  751.             if(throwNotFound){
  752.                 throw org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.newNotFoundException();
  753.             }
  754.         }
  755.        
  756.         return id_operation;
  757.     }
  758. }