JDBCAttivazionePolicyServiceSearchImpl.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.controllo_traffico.dao.jdbc;

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

  26. import org.openspcoop2.core.controllo_traffico.AttivazionePolicy;
  27. import org.openspcoop2.core.controllo_traffico.IdActivePolicy;
  28. import org.openspcoop2.core.controllo_traffico.constants.RuoloPolicy;
  29. import org.openspcoop2.core.controllo_traffico.dao.jdbc.converter.AttivazionePolicyFieldConverter;
  30. import org.openspcoop2.core.controllo_traffico.dao.jdbc.fetch.AttivazionePolicyFetch;
  31. import org.openspcoop2.generic_project.beans.CustomField;
  32. import org.openspcoop2.generic_project.beans.FunctionField;
  33. import org.openspcoop2.generic_project.beans.IField;
  34. import org.openspcoop2.generic_project.beans.InUse;
  35. import org.openspcoop2.generic_project.beans.NonNegativeNumber;
  36. import org.openspcoop2.generic_project.beans.Union;
  37. import org.openspcoop2.generic_project.beans.UnionExpression;
  38. import org.openspcoop2.generic_project.dao.jdbc.IJDBCServiceSearchWithId;
  39. import org.openspcoop2.generic_project.dao.jdbc.JDBCExpression;
  40. import org.openspcoop2.generic_project.dao.jdbc.JDBCPaginatedExpression;
  41. import org.openspcoop2.generic_project.dao.jdbc.JDBCServiceManagerProperties;
  42. import org.openspcoop2.generic_project.dao.jdbc.utils.IJDBCFetch;
  43. import org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject;
  44. import org.openspcoop2.generic_project.exception.MultipleResultException;
  45. import org.openspcoop2.generic_project.exception.NotFoundException;
  46. import org.openspcoop2.generic_project.exception.NotImplementedException;
  47. import org.openspcoop2.generic_project.exception.ServiceException;
  48. import org.openspcoop2.generic_project.expression.IExpression;
  49. import org.openspcoop2.generic_project.expression.impl.sql.ISQLFieldConverter;
  50. import org.openspcoop2.generic_project.utils.UtilsTemplate;
  51. import org.openspcoop2.utils.sql.ISQLQueryObject;
  52. import org.slf4j.Logger;

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

  61.     private AttivazionePolicyFieldConverter _attivazionePolicyFieldConverter = null;
  62.     public AttivazionePolicyFieldConverter getAttivazionePolicyFieldConverter() {
  63.         if(this._attivazionePolicyFieldConverter==null){
  64.             this._attivazionePolicyFieldConverter = new AttivazionePolicyFieldConverter(this.jdbcServiceManager.getJdbcProperties().getDatabaseType());
  65.         }      
  66.         return this._attivazionePolicyFieldConverter;
  67.     }
  68.     @Override
  69.     public ISQLFieldConverter getFieldConverter() {
  70.         return this.getAttivazionePolicyFieldConverter();
  71.     }
  72.    
  73.     private AttivazionePolicyFetch attivazionePolicyFetch = new AttivazionePolicyFetch();
  74.     public AttivazionePolicyFetch getAttivazionePolicyFetch() {
  75.         return this.attivazionePolicyFetch;
  76.     }
  77.     @Override
  78.     public IJDBCFetch getFetch() {
  79.         return getAttivazionePolicyFetch();
  80.     }
  81.    
  82.    
  83.     private JDBCServiceManager jdbcServiceManager = null;

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

  94.     @Override
  95.     public IdActivePolicy convertToId(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, AttivazionePolicy attivazionePolicy) throws NotImplementedException, ServiceException, Exception{
  96.    
  97.         IdActivePolicy idAttivazionePolicy = new IdActivePolicy();
  98.         idAttivazionePolicy.setNome(attivazionePolicy.getIdActivePolicy());
  99.        
  100.         // opzionali
  101.         idAttivazionePolicy.setIdPolicy(attivazionePolicy.getIdPolicy());
  102.         idAttivazionePolicy.setAlias(attivazionePolicy.getAlias());
  103.         idAttivazionePolicy.setEnabled(attivazionePolicy.isEnabled());
  104.         idAttivazionePolicy.setUpdateTime(attivazionePolicy.getUpdateTime());
  105.         idAttivazionePolicy.setPosizione(attivazionePolicy.getPosizione());
  106.         idAttivazionePolicy.setContinuaValutazione(attivazionePolicy.isContinuaValutazione());
  107.         if(attivazionePolicy.getFiltro()!=null) {
  108.             idAttivazionePolicy.setFiltroRuoloPorta(attivazionePolicy.getFiltro().getRuoloPorta());
  109.             idAttivazionePolicy.setFiltroNomePorta(attivazionePolicy.getFiltro().getNomePorta());
  110.         }
  111.        
  112.         return idAttivazionePolicy;
  113.        
  114.     }
  115.    
  116.     @Override
  117.     public AttivazionePolicy get(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdActivePolicy id, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotFoundException, MultipleResultException, NotImplementedException, ServiceException,Exception {
  118.         Long id_attivazionePolicy = ( (id!=null && id.getId()!=null && id.getId()>0) ? id.getId() : this.findIdAttivazionePolicy(jdbcProperties, log, connection, sqlQueryObject, id, true));
  119.         return this.getEngine(jdbcProperties, log, connection, sqlQueryObject, id_attivazionePolicy,idMappingResolutionBehaviour);
  120.        
  121.        
  122.     }
  123.    
  124.     @Override
  125.     public boolean exists(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdActivePolicy id) throws MultipleResultException, NotImplementedException, ServiceException,Exception {

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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



  375.     // -- ConstructorExpression

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


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

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

  413.     @Override
  414.     public void mappingTableIds(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdActivePolicy id, AttivazionePolicy obj) throws NotFoundException,NotImplementedException,ServiceException,Exception{
  415.         _mappingTableIds(jdbcProperties,log,connection,sqlQueryObject,obj,
  416.                 this.get(jdbcProperties,log,connection,sqlQueryObject,id,null));
  417.     }
  418.    
  419.     @Override
  420.     public void mappingTableIds(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId, AttivazionePolicy obj) throws NotFoundException,NotImplementedException,ServiceException,Exception{
  421.         _mappingTableIds(jdbcProperties,log,connection,sqlQueryObject,obj,
  422.                 this.get(jdbcProperties,log,connection,sqlQueryObject,tableId,null));
  423.     }
  424.     private void _mappingTableIds(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, AttivazionePolicy obj, AttivazionePolicy imgSaved) throws NotFoundException,NotImplementedException,ServiceException,Exception{
  425.         if(imgSaved==null){
  426.             return;
  427.         }
  428.         obj.setId(imgSaved.getId());
  429.         if(obj.getFiltro()!=null &&
  430.                 imgSaved.getFiltro()!=null){
  431.             obj.getFiltro().setId(imgSaved.getFiltro().getId());
  432.         }
  433.         if(obj.getGroupBy()!=null &&
  434.                 imgSaved.getGroupBy()!=null){
  435.             obj.getGroupBy().setId(imgSaved.getGroupBy().getId());
  436.         }

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

  453.         // Object attivazionePolicy
  454.         sqlQueryObjectGet.setANDLogicOperator(true);
  455.         sqlQueryObjectGet.addFromTable(this.getAttivazionePolicyFieldConverter().toTable(AttivazionePolicy.model()));
  456.         sqlQueryObjectGet.addSelectField("id");
  457.         sqlQueryObjectGet.addSelectField(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().ID_ACTIVE_POLICY,true));
  458.         sqlQueryObjectGet.addSelectField(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().ALIAS,true));
  459.         sqlQueryObjectGet.addSelectField(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().UPDATE_TIME,true));
  460.         sqlQueryObjectGet.addSelectField(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().POSIZIONE,true));
  461.         sqlQueryObjectGet.addSelectField(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().CONTINUA_VALUTAZIONE,true));
  462.         sqlQueryObjectGet.addSelectField(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().ID_POLICY,true));
  463.         sqlQueryObjectGet.addSelectField(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().ENABLED,true));
  464.         sqlQueryObjectGet.addSelectField(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().WARNING_ONLY,true));
  465.         sqlQueryObjectGet.addSelectField(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().RIDEFINISCI,true));
  466.         sqlQueryObjectGet.addSelectField(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().VALORE,true));
  467.         sqlQueryObjectGet.addSelectField(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().VALORE_2,true));
  468.         sqlQueryObjectGet.addSelectField(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().FILTRO.ENABLED,true));
  469.         sqlQueryObjectGet.addSelectField(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().FILTRO.PROTOCOLLO,true));
  470.         sqlQueryObjectGet.addSelectField(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().FILTRO.RUOLO_PORTA,true));
  471.         sqlQueryObjectGet.addSelectField(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().FILTRO.NOME_PORTA,true));
  472.         sqlQueryObjectGet.addSelectField(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().FILTRO.TIPO_FRUITORE,true));
  473.         sqlQueryObjectGet.addSelectField(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().FILTRO.NOME_FRUITORE,true));
  474.         sqlQueryObjectGet.addSelectField(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().FILTRO.RUOLO_FRUITORE,true));
  475.         sqlQueryObjectGet.addSelectField(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().FILTRO.SERVIZIO_APPLICATIVO_FRUITORE,true));
  476.         sqlQueryObjectGet.addSelectField(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().FILTRO.TIPO_EROGATORE,true));
  477.         sqlQueryObjectGet.addSelectField(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().FILTRO.NOME_EROGATORE,true));
  478.         sqlQueryObjectGet.addSelectField(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().FILTRO.RUOLO_EROGATORE,true));
  479.         sqlQueryObjectGet.addSelectField(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().FILTRO.SERVIZIO_APPLICATIVO_EROGATORE,true));
  480.         sqlQueryObjectGet.addSelectField(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().FILTRO.TAG,true));
  481.         sqlQueryObjectGet.addSelectField(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().FILTRO.TIPO_SERVIZIO,true));
  482.         sqlQueryObjectGet.addSelectField(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().FILTRO.NOME_SERVIZIO,true));
  483.         sqlQueryObjectGet.addSelectField(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().FILTRO.VERSIONE_SERVIZIO,true));
  484.         sqlQueryObjectGet.addSelectField(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().FILTRO.AZIONE,true));
  485.         sqlQueryObjectGet.addSelectField(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().FILTRO.TOKEN_CLAIMS,true));
  486.         sqlQueryObjectGet.addSelectField(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().FILTRO.INFORMAZIONE_APPLICATIVA_ENABLED,true));
  487.         sqlQueryObjectGet.addSelectField(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().FILTRO.INFORMAZIONE_APPLICATIVA_TIPO,true));
  488.         sqlQueryObjectGet.addSelectField(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().FILTRO.INFORMAZIONE_APPLICATIVA_NOME,true));
  489.         sqlQueryObjectGet.addSelectField(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().FILTRO.INFORMAZIONE_APPLICATIVA_VALORE,true));
  490.         sqlQueryObjectGet.addSelectField(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().GROUP_BY.ENABLED,true));
  491.         sqlQueryObjectGet.addSelectField(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().GROUP_BY.RUOLO_PORTA,true));
  492.         sqlQueryObjectGet.addSelectField(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().GROUP_BY.PROTOCOLLO,true));
  493.         sqlQueryObjectGet.addSelectField(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().GROUP_BY.FRUITORE,true));
  494.         sqlQueryObjectGet.addSelectField(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().GROUP_BY.SERVIZIO_APPLICATIVO_FRUITORE,true));
  495.         sqlQueryObjectGet.addSelectField(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().GROUP_BY.IDENTIFICATIVO_AUTENTICATO,true));
  496.         sqlQueryObjectGet.addSelectField(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().GROUP_BY.TOKEN,true));
  497.         sqlQueryObjectGet.addSelectField(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().GROUP_BY.EROGATORE,true));
  498.         sqlQueryObjectGet.addSelectField(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().GROUP_BY.SERVIZIO_APPLICATIVO_EROGATORE,true));
  499.         sqlQueryObjectGet.addSelectField(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().GROUP_BY.SERVIZIO,true));
  500.         sqlQueryObjectGet.addSelectField(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().GROUP_BY.AZIONE,true));
  501.         sqlQueryObjectGet.addSelectField(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().GROUP_BY.INFORMAZIONE_APPLICATIVA_ENABLED,true));
  502.         sqlQueryObjectGet.addSelectField(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().GROUP_BY.INFORMAZIONE_APPLICATIVA_TIPO,true));
  503.         sqlQueryObjectGet.addSelectField(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().GROUP_BY.INFORMAZIONE_APPLICATIVA_NOME,true));
  504.         sqlQueryObjectGet.addWhereCondition("id=?");

  505.         // Get attivazionePolicy
  506.         attivazionePolicy = (AttivazionePolicy) jdbcUtilities.executeQuerySingleResult(sqlQueryObjectGet.createSQLQuery(), jdbcProperties.isShowSql(), AttivazionePolicy.model(), this.getAttivazionePolicyFetch(),
  507.             new JDBCObject(tableId,Long.class));



  508.        
  509.         return attivazionePolicy;  
  510.    
  511.     }
  512.    
  513.     @Override
  514.     public boolean exists(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId) throws MultipleResultException, NotImplementedException, ServiceException, Exception {
  515.         return this._exists(jdbcProperties, log, connection, sqlQueryObject, Long.valueOf(tableId));
  516.     }
  517.    
  518.     private boolean _exists(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, Long tableId) throws MultipleResultException, NotImplementedException, ServiceException, Exception {
  519.    
  520.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  521.                     new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);
  522.                
  523.         boolean existsAttivazionePolicy = false;

  524.         sqlQueryObject = sqlQueryObject.newSQLQueryObject();
  525.         sqlQueryObject.setANDLogicOperator(true);

  526.         sqlQueryObject.addFromTable(this.getAttivazionePolicyFieldConverter().toTable(AttivazionePolicy.model()));
  527.         sqlQueryObject.addSelectField(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().ID_ACTIVE_POLICY,true));
  528.         sqlQueryObject.addWhereCondition("id=?");


  529.         // Exists attivazionePolicy
  530.         existsAttivazionePolicy = jdbcUtilities.exists(sqlQueryObject.createSQLQuery(), jdbcProperties.isShowSql(),
  531.             new JDBCObject(tableId,Long.class));

  532.        
  533.         return existsAttivazionePolicy;
  534.    
  535.     }
  536.    
  537.     private void joinEngine(IExpression expression, ISQLQueryObject sqlQueryObject) throws NotImplementedException, ServiceException, Exception{
  538.    
  539.        
  540.     }
  541.    
  542.     protected java.util.List<Object> getRootTablePrimaryKeyValuesEngine(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdActivePolicy id) throws NotFoundException, ServiceException, NotImplementedException, Exception{
  543.         // Identificativi
  544.         java.util.List<Object> rootTableIdValues = new java.util.ArrayList<>();
  545.         Long longId = this.findIdAttivazionePolicy(jdbcProperties, log, connection, sqlQueryObject.newSQLQueryObject(), id, true);
  546.         rootTableIdValues.add(longId);
  547.        
  548.         return rootTableIdValues;
  549.     }
  550.    
  551.     protected Map<String, List<IField>> getMapTableToPKColumnEngine() throws NotImplementedException, Exception{
  552.    
  553.         AttivazionePolicyFieldConverter converter = this.getAttivazionePolicyFieldConverter();
  554.         Map<String, List<IField>> mapTableToPKColumn = new java.util.HashMap<>();
  555.         UtilsTemplate<IField> utilities = new UtilsTemplate<>();

  556.         // AttivazionePolicy.model()
  557.         mapTableToPKColumn.put(converter.toTable(AttivazionePolicy.model()),
  558.             utilities.newList(
  559.                 new CustomField("id", Long.class, "id", converter.toTable(AttivazionePolicy.model()))
  560.             ));
  561.        
  562.         return mapTableToPKColumn;      
  563.     }
  564.    
  565.     @Override
  566.     public List<Long> findAllTableIds(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCPaginatedExpression paginatedExpression) throws ServiceException, NotImplementedException, Exception {
  567.        
  568.         List<Long> list = new ArrayList<Long>();

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

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

  600.         Object res = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.find(jdbcProperties, log, connection, sqlQueryObject, expression,
  601.                                                         this.getAttivazionePolicyFieldConverter(), AttivazionePolicy.model(), objectIdClass, listaQuery);
  602.         if(res!=null && (((Long) res).longValue()>0) ){
  603.             return ((Long) res).longValue();
  604.         }
  605.         else{
  606.             throw org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.newNotFoundException();
  607.         }
  608.        
  609.     }

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

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

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

  628.         return inUse;

  629.     }
  630.    
  631.     @Override
  632.     public IdActivePolicy findId(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId, boolean throwNotFound)
  633.             throws NotFoundException, ServiceException, NotImplementedException, Exception {
  634.        
  635.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  636.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);

  637.         ISQLQueryObject sqlQueryObjectGet = sqlQueryObject.newSQLQueryObject();

  638.         // Object _attivazionePolicy
  639.         sqlQueryObjectGet.addFromTable(this.getAttivazionePolicyFieldConverter().toTable(AttivazionePolicy.model()));
  640.         sqlQueryObjectGet.addSelectField(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().ID_ACTIVE_POLICY,true));
  641.         sqlQueryObjectGet.addSelectField(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().ALIAS,true));
  642.         sqlQueryObjectGet.addSelectField(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().ID_POLICY,true));
  643.         sqlQueryObjectGet.addSelectField(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().ENABLED,true));
  644.         sqlQueryObjectGet.addSelectField(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().UPDATE_TIME,true));
  645.         sqlQueryObjectGet.addSelectField(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().POSIZIONE,true));
  646.         sqlQueryObjectGet.addSelectField(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().CONTINUA_VALUTAZIONE,true));
  647.         sqlQueryObjectGet.addSelectField(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().FILTRO.RUOLO_PORTA,true));
  648.         sqlQueryObjectGet.addSelectField(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().FILTRO.NOME_PORTA,true));
  649.         sqlQueryObjectGet.setANDLogicOperator(true);
  650.         sqlQueryObjectGet.addWhereCondition("id=?");

  651.         // Recupero _attivazionePolicy
  652.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject [] searchParams_attivazionePolicy = new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject [] {
  653.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(tableId,Long.class)
  654.         };
  655.         List<Class<?>> listaFieldIdReturnType_attivazionePolicy = new ArrayList<Class<?>>();
  656.         listaFieldIdReturnType_attivazionePolicy.add(AttivazionePolicy.model().ID_ACTIVE_POLICY.getFieldType());
  657.         listaFieldIdReturnType_attivazionePolicy.add(AttivazionePolicy.model().ALIAS.getFieldType());
  658.         listaFieldIdReturnType_attivazionePolicy.add(AttivazionePolicy.model().ID_POLICY.getFieldType());
  659.         listaFieldIdReturnType_attivazionePolicy.add(AttivazionePolicy.model().ENABLED.getFieldType());
  660.         listaFieldIdReturnType_attivazionePolicy.add(AttivazionePolicy.model().UPDATE_TIME.getFieldType());
  661.         listaFieldIdReturnType_attivazionePolicy.add(AttivazionePolicy.model().POSIZIONE.getFieldType());
  662.         listaFieldIdReturnType_attivazionePolicy.add(AttivazionePolicy.model().CONTINUA_VALUTAZIONE.getFieldType());
  663.         listaFieldIdReturnType_attivazionePolicy.add(AttivazionePolicy.model().FILTRO.RUOLO_PORTA.getFieldType());
  664.         listaFieldIdReturnType_attivazionePolicy.add(AttivazionePolicy.model().FILTRO.NOME_PORTA.getFieldType());
  665.         org.openspcoop2.core.controllo_traffico.IdActivePolicy id_attivazionePolicy = null;
  666.         List<Object> listaFieldId_attivazionePolicy = jdbcUtilities.executeQuerySingleResult(sqlQueryObjectGet.createSQLQuery(), jdbcProperties.isShowSql(),
  667.                 listaFieldIdReturnType_attivazionePolicy, searchParams_attivazionePolicy);
  668.         if(listaFieldId_attivazionePolicy==null || listaFieldId_attivazionePolicy.size()<=0){
  669.             if(throwNotFound){
  670.                 throw org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.newNotFoundException();
  671.             }
  672.         }
  673.         else{
  674.             // set _attivazionePolicy
  675.             id_attivazionePolicy = new org.openspcoop2.core.controllo_traffico.IdActivePolicy();
  676.             id_attivazionePolicy.setNome((String)listaFieldId_attivazionePolicy.get(0));
  677.             id_attivazionePolicy.setAlias((String)listaFieldId_attivazionePolicy.get(1));
  678.             id_attivazionePolicy.setIdPolicy((String)listaFieldId_attivazionePolicy.get(2));
  679.             id_attivazionePolicy.setEnabled((Boolean)listaFieldId_attivazionePolicy.get(3));
  680.             id_attivazionePolicy.setUpdateTime((Date)listaFieldId_attivazionePolicy.get(4));
  681.             Object posizione = listaFieldId_attivazionePolicy.get(5);
  682.             if(posizione instanceof Integer) {
  683.                 id_attivazionePolicy.setPosizione((Integer)posizione);
  684.             }
  685.             id_attivazionePolicy.setContinuaValutazione((Boolean)listaFieldId_attivazionePolicy.get(6));
  686.             Object ruoloPorta = listaFieldId_attivazionePolicy.get(7);
  687.             if(ruoloPorta!=null) {
  688.                 if(ruoloPorta instanceof RuoloPolicy) {
  689.                     id_attivazionePolicy.setFiltroRuoloPorta((RuoloPolicy)ruoloPorta);
  690.                 }
  691.                 else if(ruoloPorta instanceof String) {
  692.                     id_attivazionePolicy.setFiltroRuoloPorta(RuoloPolicy.toEnumConstant((String)ruoloPorta));
  693.                 }
  694.             }
  695.             Object nomePorta = listaFieldId_attivazionePolicy.get(8);
  696.             if(nomePorta!=null) {
  697.                 if(nomePorta instanceof String) {
  698.                     id_attivazionePolicy.setFiltroNomePorta((String)nomePorta);
  699.                 }
  700.             }
  701.         }
  702.        
  703.         return id_attivazionePolicy;
  704.        
  705.     }

  706.     @Override
  707.     public Long findTableId(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdActivePolicy id, boolean throwNotFound)
  708.             throws NotFoundException, ServiceException, NotImplementedException, Exception {
  709.    
  710.         return this.findIdAttivazionePolicy(jdbcProperties,log,connection,sqlQueryObject,id,throwNotFound);
  711.            
  712.     }
  713.    
  714.     @Override
  715.     public List<List<Object>> nativeQuery(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  716.                                             String sql,List<Class<?>> returnClassTypes,Object ... param) throws ServiceException,NotFoundException,NotImplementedException,Exception{
  717.        
  718.         return org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.nativeQuery(jdbcProperties, log, connection, sqlQueryObject,
  719.                                                                                             sql,returnClassTypes,param);
  720.                                                        
  721.     }
  722.    
  723.     protected Long findIdAttivazionePolicy(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdActivePolicy id, boolean throwNotFound) throws NotFoundException, ServiceException, NotImplementedException, Exception {

  724.         if(jdbcProperties==null) {
  725.             throw new ServiceException("Param jdbcProperties is null");
  726.         }
  727.         if(sqlQueryObject==null) {
  728.             throw new ServiceException("Param sqlQueryObject is null");
  729.         }
  730.         if(id==null) {
  731.             throw new ServiceException("Param id is null");
  732.         }
  733.        
  734.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  735.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);

  736.         ISQLQueryObject sqlQueryObjectGet = sqlQueryObject.newSQLQueryObject();

  737.         // Object _attivazionePolicy
  738.         sqlQueryObjectGet.addFromTable(this.getAttivazionePolicyFieldConverter().toTable(AttivazionePolicy.model()));
  739.         sqlQueryObjectGet.addSelectField("id");
  740.         // Devono essere mappati nella where condition i metodi dell'oggetto id.getXXX
  741.         sqlQueryObjectGet.setANDLogicOperator(true);
  742.         sqlQueryObjectGet.setSelectDistinct(true);
  743.         sqlQueryObjectGet.addWhereCondition(this.getAttivazionePolicyFieldConverter().toColumn(AttivazionePolicy.model().ID_ACTIVE_POLICY,true)+"=?");

  744.         // Recupero _attivazionePolicy
  745.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject [] searchParams_attivazionePolicy = new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject [] {
  746.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(id.getNome(),String.class)
  747.         };
  748.         Long id_attivazionePolicy = null;
  749.         try{
  750.             id_attivazionePolicy = (Long) jdbcUtilities.executeQuerySingleResult(sqlQueryObjectGet.createSQLQuery(), jdbcProperties.isShowSql(),
  751.                         Long.class, searchParams_attivazionePolicy);
  752.         }catch(NotFoundException notFound){
  753.             if(throwNotFound){
  754.                 throw new NotFoundException(notFound);
  755.             }
  756.         }
  757.         if(id_attivazionePolicy==null || id_attivazionePolicy<=0){
  758.             if(throwNotFound){
  759.                 throw org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.newNotFoundException();
  760.             }
  761.         }
  762.        
  763.         return id_attivazionePolicy;
  764.     }
  765. }