JDBCEventoServiceSearchImpl.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.eventi.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.IJDBCServiceSearchWithoutId;
  31. import org.openspcoop2.generic_project.utils.UtilsTemplate;
  32. import org.openspcoop2.generic_project.beans.CustomField;
  33. import org.openspcoop2.generic_project.beans.InUse;
  34. import org.openspcoop2.generic_project.beans.IField;
  35. import org.openspcoop2.generic_project.beans.NonNegativeNumber;
  36. import org.openspcoop2.generic_project.beans.UnionExpression;
  37. import org.openspcoop2.generic_project.beans.Union;
  38. import org.openspcoop2.generic_project.beans.FunctionField;
  39. import org.openspcoop2.generic_project.exception.MultipleResultException;
  40. import org.openspcoop2.generic_project.exception.NotFoundException;
  41. import org.openspcoop2.generic_project.exception.NotImplementedException;
  42. import org.openspcoop2.generic_project.exception.ServiceException;
  43. import org.openspcoop2.generic_project.expression.IExpression;
  44. import org.openspcoop2.generic_project.dao.jdbc.JDBCExpression;
  45. import org.openspcoop2.generic_project.dao.jdbc.JDBCPaginatedExpression;

  46. import org.openspcoop2.generic_project.dao.jdbc.JDBCServiceManagerProperties;
  47. import org.openspcoop2.core.eventi.dao.jdbc.converter.EventoFieldConverter;
  48. import org.openspcoop2.core.eventi.dao.jdbc.fetch.EventoFetch;
  49. import org.openspcoop2.core.eventi.Evento;

  50. /**    
  51.  * JDBCEventoServiceSearchImpl
  52.  *
  53.  * @author Poli Andrea (poli@link.it)
  54.  * @author $Author$
  55.  * @version $Rev$, $Date$
  56.  */
  57. public class JDBCEventoServiceSearchImpl implements IJDBCServiceSearchWithoutId<Evento, JDBCServiceManager> {

  58.     private EventoFieldConverter _eventoFieldConverter = null;
  59.     public EventoFieldConverter getEventoFieldConverter() {
  60.         if(this._eventoFieldConverter==null){
  61.             this._eventoFieldConverter = new EventoFieldConverter(this.jdbcServiceManager.getJdbcProperties().getDatabaseType());
  62.         }      
  63.         return this._eventoFieldConverter;
  64.     }
  65.     @Override
  66.     public ISQLFieldConverter getFieldConverter() {
  67.         return this.getEventoFieldConverter();
  68.     }
  69.    
  70.     private EventoFetch eventoFetch = new EventoFetch();
  71.     public EventoFetch getEventoFetch() {
  72.         return this.eventoFetch;
  73.     }
  74.     @Override
  75.     public IJDBCFetch getFetch() {
  76.         return getEventoFetch();
  77.     }
  78.    
  79.    
  80.     private JDBCServiceManager jdbcServiceManager = null;

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

  91.    
  92.    
  93.     private static boolean efficiente = true;
  94.     public static boolean isEfficiente() {
  95.         return efficiente;
  96.     }
  97.     public static void setEfficiente(boolean efficiente) {
  98.         JDBCEventoServiceSearchImpl.efficiente = efficiente;
  99.     }
  100.     @Override
  101.     public List<Evento> findAll(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCPaginatedExpression expression, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotImplementedException, ServiceException,Exception {

  102.         List<Evento> list = new ArrayList<Evento>();
  103.        
  104.         if(efficiente){
  105.            
  106.             List<IField> fields = new ArrayList<IField>();
  107.             fields.add(new CustomField("id", Long.class, "id", this.getEventoFieldConverter().toTable(Evento.model())));  
  108.             fields.add(Evento.model().TIPO);
  109.             fields.add(Evento.model().CODICE);
  110.             fields.add(Evento.model().SEVERITA);
  111.             fields.add(Evento.model().ORA_REGISTRAZIONE);
  112.             fields.add(Evento.model().DESCRIZIONE);
  113.             fields.add(Evento.model().ID_TRANSAZIONE);
  114.             fields.add(Evento.model().ID_CONFIGURAZIONE);
  115.             fields.add(Evento.model().CONFIGURAZIONE);
  116.             fields.add(Evento.model().CLUSTER_ID);
  117.                
  118.             List<Map<String, Object>> returnMap = null;
  119.             try{
  120.                 boolean distinct = false; // e' piu' efficiente senza il distinct
  121.                 returnMap = this.select(jdbcProperties, log, connection, sqlQueryObject, expression, distinct, fields.toArray(new IField[1]));
  122.    
  123.                 for(Map<String, Object> map: returnMap) {
  124.                     list.add((Evento)this.getEventoFetch().fetch(jdbcProperties.getDatabase(), Evento.model(), map));
  125.                 }
  126.             }catch(NotFoundException notFound){}
  127.         }
  128.         else{

  129.             List<Long> ids = this.findAllTableIds(jdbcProperties, log, connection, sqlQueryObject, expression);
  130.            
  131.             for(Long id: ids) {
  132.                 list.add(this.get(jdbcProperties, log, connection, sqlQueryObject, id, idMappingResolutionBehaviour));
  133.             }
  134.            
  135.         }

  136.         return list;      
  137.        
  138.     }
  139.    
  140.     @Override
  141.     public Evento find(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCExpression expression, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour)
  142.         throws NotFoundException, MultipleResultException, NotImplementedException, ServiceException,Exception {

  143.         long id = this.findTableId(jdbcProperties, log, connection, sqlQueryObject, expression);
  144.         if(id>0){
  145.             return this.get(jdbcProperties, log, connection, sqlQueryObject, id, idMappingResolutionBehaviour);
  146.         }else{
  147.             throw new NotFoundException("Entry with id["+id+"] not found");
  148.         }
  149.        
  150.     }
  151.    
  152.     @Override
  153.     public NonNegativeNumber count(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCExpression expression) throws NotImplementedException, ServiceException,Exception {
  154.        
  155.         List<Object> listaQuery = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareCount(jdbcProperties, log, connection, sqlQueryObject, expression,
  156.                                                 this.getEventoFieldConverter(), Evento.model());
  157.        
  158.         boolean distinct = false; // e' piu' efficiente senza il distinct
  159.         if(!distinct && expression.inUseField(Evento.model().ORA_REGISTRAZIONE, true)){
  160.             // uso la prima colonna dell'indice (se c'è la data e non è distinct)
  161.             sqlQueryObject.addSelectCountField(this.getEventoFieldConverter().toColumn(Evento.model().ORA_REGISTRAZIONE, true),"tot",distinct);
  162.         }
  163.         else{
  164.             sqlQueryObject.addSelectCountField(this.getEventoFieldConverter().toTable(Evento.model())+".id","tot",distinct);
  165.         }
  166.        
  167.         joinEngine(expression,sqlQueryObject);
  168.        
  169.         return org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.count(jdbcProperties, log, connection, sqlQueryObject, expression,
  170.                                                                             this.getEventoFieldConverter(), Evento.model(),listaQuery);
  171.     }


  172.     @Override
  173.     public List<Object> select(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  174.                                                     JDBCPaginatedExpression paginatedExpression, IField field) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  175.         return this.select(jdbcProperties, log, connection, sqlQueryObject,
  176.                                 paginatedExpression, false, field);
  177.     }
  178.    
  179.     @Override
  180.     public List<Object> select(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  181.                                                     JDBCPaginatedExpression paginatedExpression, boolean distinct, IField field) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  182.         List<Map<String,Object>> map =
  183.             this.select(jdbcProperties, log, connection, sqlQueryObject, paginatedExpression, distinct, new IField[]{field});
  184.         return org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.selectSingleObject(map);
  185.     }
  186.    
  187.     @Override
  188.     public List<Map<String,Object>> select(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  189.                                                     JDBCPaginatedExpression paginatedExpression, IField ... field) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  190.         return this.select(jdbcProperties, log, connection, sqlQueryObject,
  191.                                 paginatedExpression, false, field);
  192.     }
  193.    
  194.     @Override
  195.     public List<Map<String,Object>> select(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  196.                                                     JDBCPaginatedExpression paginatedExpression, boolean distinct, IField ... field) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  197.        
  198.         org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.setFields(sqlQueryObject,paginatedExpression,field);
  199.         try{
  200.        
  201.             ISQLQueryObject sqlQueryObjectDistinct =
  202.                         org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareSqlQueryObjectForSelectDistinct(distinct,sqlQueryObject, paginatedExpression, log,
  203.                                                 this.getEventoFieldConverter(), field);

  204.             return selectEngine(jdbcProperties, log, connection, sqlQueryObject, paginatedExpression, sqlQueryObjectDistinct);
  205.            
  206.         }finally{
  207.             org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.removeFields(sqlQueryObject,paginatedExpression,field);
  208.         }
  209.     }

  210.     @Override
  211.     public Object aggregate(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  212.                                                     JDBCExpression expression, FunctionField functionField) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  213.         Map<String,Object> map =
  214.             this.aggregate(jdbcProperties, log, connection, sqlQueryObject, expression, new FunctionField[]{functionField});
  215.         return org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.selectAggregateObject(map,functionField);
  216.     }
  217.    
  218.     @Override
  219.     public Map<String,Object> aggregate(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  220.                                                     JDBCExpression expression, FunctionField ... functionField) throws ServiceException,NotFoundException,NotImplementedException,Exception {                                                  
  221.        
  222.         org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.setFields(sqlQueryObject,expression,functionField);
  223.         try{
  224.             List<Map<String,Object>> list = selectEngine(jdbcProperties, log, connection, sqlQueryObject, expression);
  225.             return list.get(0);
  226.         }finally{
  227.             org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.removeFields(sqlQueryObject,expression,functionField);
  228.         }
  229.     }

  230.     @Override
  231.     public List<Map<String,Object>> groupBy(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  232.                                                     JDBCExpression expression, FunctionField ... functionField) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  233.        
  234.         if(expression.getGroupByFields().isEmpty()){
  235.             throw new ServiceException("GroupBy conditions not found in expression");
  236.         }
  237.        
  238.         org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.setFields(sqlQueryObject,expression,functionField);
  239.         try{
  240.             return selectEngine(jdbcProperties, log, connection, sqlQueryObject, expression);
  241.         }finally{
  242.             org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.removeFields(sqlQueryObject,expression,functionField);
  243.         }
  244.     }
  245.    

  246.     @Override
  247.     public List<Map<String,Object>> groupBy(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  248.                                                     JDBCPaginatedExpression paginatedExpression, FunctionField ... functionField) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  249.        
  250.         if(paginatedExpression.getGroupByFields().isEmpty()){
  251.             throw new ServiceException("GroupBy conditions not found in expression");
  252.         }
  253.        
  254.         org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.setFields(sqlQueryObject,paginatedExpression,functionField);
  255.         try{
  256.             return selectEngine(jdbcProperties, log, connection, sqlQueryObject, paginatedExpression);
  257.         }finally{
  258.             org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.removeFields(sqlQueryObject,paginatedExpression,functionField);
  259.         }
  260.     }
  261.    
  262.     protected List<Map<String,Object>> selectEngine(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  263.                                                 IExpression expression) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  264.         return selectEngine(jdbcProperties, log, connection, sqlQueryObject, expression, null);
  265.     }
  266.     protected List<Map<String,Object>> selectEngine(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  267.                                                 IExpression expression, ISQLQueryObject sqlQueryObjectDistinct) throws ServiceException,NotFoundException,NotImplementedException,Exception {
  268.        
  269.         List<Object> listaQuery = new ArrayList<>();
  270.         List<JDBCObject> listaParams = new ArrayList<>();
  271.         List<Object> returnField = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareSelect(jdbcProperties, log, connection, sqlQueryObject,
  272.                                 expression, this.getEventoFieldConverter(), Evento.model(),
  273.                                 listaQuery,listaParams);
  274.        
  275.         joinEngine(expression,sqlQueryObject);
  276.        
  277.         List<Map<String,Object>> list = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.select(jdbcProperties, log, connection,
  278.                                         org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareSqlQueryObjectForSelectDistinct(sqlQueryObject,sqlQueryObjectDistinct),
  279.                                         expression, this.getEventoFieldConverter(), Evento.model(),
  280.                                         listaQuery,listaParams,returnField);
  281.         if(list!=null && !list.isEmpty()){
  282.             return list;
  283.         }
  284.         else{
  285.             throw org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.newNotFoundException();
  286.         }
  287.     }
  288.    
  289.     @Override
  290.     public List<Map<String,Object>> union(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  291.                                                 Union union, UnionExpression ... unionExpression) throws ServiceException,NotFoundException,NotImplementedException,Exception {    
  292.        
  293.         List<ISQLQueryObject> sqlQueryObjectInnerList = new ArrayList<>();
  294.         List<JDBCObject> jdbcObjects = new ArrayList<>();
  295.         List<Class<?>> returnClassTypes = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareUnion(jdbcProperties, log, connection, sqlQueryObject,
  296.                                 this.getEventoFieldConverter(), Evento.model(),
  297.                                 sqlQueryObjectInnerList, jdbcObjects, union, unionExpression);
  298.        
  299.         if(unionExpression!=null){
  300.             for (int i = 0; i < unionExpression.length; i++) {
  301.                 UnionExpression ue = unionExpression[i];
  302.                 IExpression expression = ue.getExpression();
  303.                 joinEngine(expression,sqlQueryObjectInnerList.get(i));
  304.             }
  305.         }
  306.        
  307.         List<Map<String,Object>> list = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.union(jdbcProperties, log, connection, sqlQueryObject,
  308.                                         this.getEventoFieldConverter(), Evento.model(),
  309.                                         sqlQueryObjectInnerList, jdbcObjects, returnClassTypes, union, unionExpression);
  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 NonNegativeNumber unionCount(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.prepareUnionCount(jdbcProperties, log, connection, sqlQueryObject,
  325.                                 this.getEventoFieldConverter(), Evento.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.         NonNegativeNumber number = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.unionCount(jdbcProperties, log, connection, sqlQueryObject,
  337.                                         this.getEventoFieldConverter(), Evento.model(),
  338.                                         sqlQueryObjectInnerList, jdbcObjects, returnClassTypes, union, unionExpression);
  339.         if(number!=null && number.longValue()>=0){
  340.             return number;
  341.         }
  342.         else{
  343.             throw org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.newNotFoundException();
  344.         }
  345.     }



  346.     // -- ConstructorExpression

  347.     @Override
  348.     public JDBCExpression newExpression(Logger log) throws NotImplementedException, ServiceException {
  349.         try{
  350.             return new JDBCExpression(this.getEventoFieldConverter());
  351.         }catch(Exception e){
  352.             throw new ServiceException(e);
  353.         }
  354.     }


  355.     @Override
  356.     public JDBCPaginatedExpression newPaginatedExpression(Logger log) throws NotImplementedException, ServiceException {
  357.         try{
  358.             return new JDBCPaginatedExpression(this.getEventoFieldConverter());
  359.         }catch(Exception e){
  360.             throw new ServiceException(e);
  361.         }
  362.     }
  363.    
  364.     @Override
  365.     public JDBCExpression toExpression(JDBCPaginatedExpression paginatedExpression, Logger log) throws NotImplementedException, ServiceException {
  366.         try{
  367.             return new JDBCExpression(paginatedExpression);
  368.         }catch(Exception e){
  369.             throw new ServiceException(e);
  370.         }
  371.     }

  372.     @Override
  373.     public JDBCPaginatedExpression toPaginatedExpression(JDBCExpression expression, Logger log) throws NotImplementedException, ServiceException {
  374.         try{
  375.             return new JDBCPaginatedExpression(expression);
  376.         }catch(Exception e){
  377.             throw new ServiceException(e);
  378.         }
  379.     }
  380.    
  381.    
  382.    
  383.     // -- DB

  384.    
  385.     @Override
  386.     public Evento get(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotFoundException, MultipleResultException, NotImplementedException, ServiceException, Exception {
  387.         return this.getEngine(jdbcProperties, log, connection, sqlQueryObject, Long.valueOf(tableId), idMappingResolutionBehaviour);
  388.     }
  389.    
  390.     private Evento getEngine(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, Long tableId, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotFoundException, MultipleResultException, NotImplementedException, ServiceException, Exception {
  391.    
  392.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  393.                     new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);
  394.        
  395.         ISQLQueryObject sqlQueryObjectGet = sqlQueryObject.newSQLQueryObject();
  396.                
  397.         Evento evento = new Evento();
  398.        

  399.         // Object evento
  400.         ISQLQueryObject sqlQueryObjectGet_evento = sqlQueryObjectGet.newSQLQueryObject();
  401.         sqlQueryObjectGet_evento.setANDLogicOperator(true);
  402.         sqlQueryObjectGet_evento.addFromTable(this.getEventoFieldConverter().toTable(Evento.model()));
  403.         sqlQueryObjectGet_evento.addSelectField("id");
  404.         sqlQueryObjectGet_evento.addSelectField(this.getEventoFieldConverter().toColumn(Evento.model().TIPO,true));
  405.         sqlQueryObjectGet_evento.addSelectField(this.getEventoFieldConverter().toColumn(Evento.model().CODICE,true));
  406.         sqlQueryObjectGet_evento.addSelectField(this.getEventoFieldConverter().toColumn(Evento.model().SEVERITA,true));
  407.         sqlQueryObjectGet_evento.addSelectField(this.getEventoFieldConverter().toColumn(Evento.model().ORA_REGISTRAZIONE,true));
  408.         sqlQueryObjectGet_evento.addSelectField(this.getEventoFieldConverter().toColumn(Evento.model().DESCRIZIONE,true));
  409.         sqlQueryObjectGet_evento.addSelectField(this.getEventoFieldConverter().toColumn(Evento.model().ID_TRANSAZIONE,true));
  410.         sqlQueryObjectGet_evento.addSelectField(this.getEventoFieldConverter().toColumn(Evento.model().ID_CONFIGURAZIONE,true));
  411.         sqlQueryObjectGet_evento.addSelectField(this.getEventoFieldConverter().toColumn(Evento.model().CONFIGURAZIONE,true));
  412.         sqlQueryObjectGet_evento.addSelectField(this.getEventoFieldConverter().toColumn(Evento.model().CLUSTER_ID,true));
  413.         sqlQueryObjectGet_evento.addWhereCondition("id=?");

  414.         // Get evento
  415.         evento = (Evento) jdbcUtilities.executeQuerySingleResult(sqlQueryObjectGet_evento.createSQLQuery(), jdbcProperties.isShowSql(), Evento.model(), this.getEventoFetch(),
  416.             new JDBCObject(tableId,Long.class));



  417.        
  418.         return evento;  
  419.    
  420.     }
  421.    
  422.     @Override
  423.     public boolean exists(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId) throws MultipleResultException, NotImplementedException, ServiceException, Exception {
  424.         return this._exists(jdbcProperties, log, connection, sqlQueryObject, Long.valueOf(tableId));
  425.     }
  426.    
  427.     private boolean _exists(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, Long tableId) throws MultipleResultException, NotImplementedException, ServiceException, Exception {
  428.    
  429.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  430.                     new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);
  431.                
  432.         boolean existsEvento = false;

  433.         sqlQueryObject = sqlQueryObject.newSQLQueryObject();
  434.         sqlQueryObject.setANDLogicOperator(true);

  435.         sqlQueryObject.addFromTable(this.getEventoFieldConverter().toTable(Evento.model()));
  436.         sqlQueryObject.addSelectField(this.getEventoFieldConverter().toColumn(Evento.model().TIPO,true));
  437.         sqlQueryObject.addWhereCondition("id=?");


  438.         // Exists evento
  439.         existsEvento = jdbcUtilities.exists(sqlQueryObject.createSQLQuery(), jdbcProperties.isShowSql(),
  440.             new JDBCObject(tableId,Long.class));

  441.        
  442.         return existsEvento;
  443.    
  444.     }
  445.    
  446.     private void joinEngine(IExpression expression, ISQLQueryObject sqlQueryObject) throws NotImplementedException, ServiceException, Exception{
  447.    
  448.         // nop;
  449.        
  450.     }
  451.    
  452.     protected java.util.List<Object> getRootTablePrimaryKeyValuesEngine(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, Evento evento) throws NotFoundException, ServiceException, NotImplementedException, Exception{
  453.         // Identificativi
  454.         java.util.List<Object> rootTableIdValues = new java.util.ArrayList<>();
  455.         rootTableIdValues.add(evento.getId());
  456.                
  457.         return rootTableIdValues;
  458.     }
  459.    
  460.     protected Map<String, List<IField>> getMapTableToPKColumnEngine() throws NotImplementedException, Exception{
  461.    
  462.         EventoFieldConverter converter = this.getEventoFieldConverter();
  463.         Map<String, List<IField>> mapTableToPKColumn = new java.util.HashMap<>();
  464.         UtilsTemplate<IField> utilities = new UtilsTemplate<>();

  465.         // Evento.model()
  466.         mapTableToPKColumn.put(converter.toTable(Evento.model()),
  467.             utilities.newList(
  468.                 new CustomField("id", Long.class, "id", converter.toTable(Evento.model()))
  469.             ));
  470.        
  471.         return mapTableToPKColumn;      
  472.     }
  473.    
  474.     @Override
  475.     public List<Long> findAllTableIds(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCPaginatedExpression paginatedExpression) throws ServiceException, NotImplementedException, Exception {
  476.        
  477.         List<Long> list = new ArrayList<Long>();

  478.         boolean distinct = false; // e' piu' efficiente senza il distinct
  479.        
  480.         sqlQueryObject.setSelectDistinct(distinct);
  481.         sqlQueryObject.setANDLogicOperator(true);
  482.         sqlQueryObject.addSelectField(this.getEventoFieldConverter().toTable(Evento.model())+".id");
  483.         Class<?> objectIdClass = Long.class;
  484.        
  485.         List<Object> listaQuery = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareFindAll(jdbcProperties, log, connection, sqlQueryObject, paginatedExpression,
  486.                                                 this.getEventoFieldConverter(), Evento.model());
  487.        
  488.         joinEngine(paginatedExpression,sqlQueryObject);
  489.        
  490.         List<Object> listObjects = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.findAll(jdbcProperties, log, connection, sqlQueryObject, paginatedExpression,
  491.                                                                             this.getEventoFieldConverter(), Evento.model(), objectIdClass, listaQuery);
  492.         for(Object object: listObjects) {
  493.             list.add((Long)object);
  494.         }

  495.         return list;
  496.        
  497.     }
  498.    
  499.     @Override
  500.     public long findTableId(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCExpression expression) throws ServiceException, NotFoundException, MultipleResultException, NotImplementedException, Exception {
  501.    
  502.         boolean distinct = false; // e' piu' efficiente senza il distinct
  503.        
  504.         sqlQueryObject.setSelectDistinct(distinct);
  505.         sqlQueryObject.setANDLogicOperator(true);
  506.         sqlQueryObject.addSelectField(this.getEventoFieldConverter().toTable(Evento.model())+".id");
  507.         Class<?> objectIdClass = Long.class;
  508.        
  509.         List<Object> listaQuery = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareFind(jdbcProperties, log, connection, sqlQueryObject, expression,
  510.                                                 this.getEventoFieldConverter(), Evento.model());
  511.        
  512.         joinEngine(expression,sqlQueryObject);

  513.         Object res = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.find(jdbcProperties, log, connection, sqlQueryObject, expression,
  514.                                                         this.getEventoFieldConverter(), Evento.model(), objectIdClass, listaQuery);
  515.         if(res!=null && (((Long) res).longValue()>0) ){
  516.             return ((Long) res).longValue();
  517.         }
  518.         else{
  519.             throw org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.newNotFoundException();
  520.         }
  521.        
  522.     }

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

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

  528.         InUse inUse = new InUse();
  529.         inUse.setInUse(false);
  530.        
  531.         /*
  532.          * TODO: implement code that checks whether the object identified by the id parameter is used by other objects
  533.         */
  534.        
  535.         // Delete this line when you have implemented the method
  536.         int throwNotImplemented = 1;
  537.         if(throwNotImplemented==1){
  538.                 throw new NotImplementedException("NotImplemented");
  539.         }
  540.         // Delete this line when you have implemented the method

  541.         return inUse;

  542.     }
  543.    

  544.    
  545.     @Override
  546.     public List<List<Object>> nativeQuery(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  547.                                             String sql,List<Class<?>> returnClassTypes,Object ... param) throws ServiceException,NotFoundException,NotImplementedException,Exception{
  548.        
  549.         return org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.nativeQuery(jdbcProperties, log, connection, sqlQueryObject,
  550.                                                                                             sql,returnClassTypes,param);
  551.                                                        
  552.     }
  553.    
  554. }