JDBCPluginServiceSearchImpl.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.plugins.dao.jdbc;

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

  25. import org.openspcoop2.generic_project.beans.CustomField;
  26. import org.openspcoop2.generic_project.beans.FunctionField;
  27. import org.openspcoop2.generic_project.beans.IField;
  28. import org.openspcoop2.generic_project.beans.InUse;
  29. import org.openspcoop2.generic_project.beans.NonNegativeNumber;
  30. import org.openspcoop2.generic_project.beans.Union;
  31. import org.openspcoop2.generic_project.beans.UnionExpression;
  32. import org.openspcoop2.generic_project.dao.jdbc.IJDBCServiceSearchWithId;
  33. import org.openspcoop2.generic_project.dao.jdbc.JDBCExpression;
  34. import org.openspcoop2.generic_project.dao.jdbc.JDBCPaginatedExpression;
  35. import org.openspcoop2.generic_project.dao.jdbc.JDBCServiceManagerProperties;
  36. import org.openspcoop2.generic_project.dao.jdbc.utils.IJDBCFetch;
  37. import org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject;
  38. import org.openspcoop2.generic_project.exception.MultipleResultException;
  39. import org.openspcoop2.generic_project.exception.NotFoundException;
  40. import org.openspcoop2.generic_project.exception.NotImplementedException;
  41. import org.openspcoop2.generic_project.exception.ServiceException;
  42. import org.openspcoop2.generic_project.expression.IExpression;
  43. import org.openspcoop2.generic_project.expression.impl.sql.ISQLFieldConverter;
  44. import org.openspcoop2.generic_project.utils.UtilsTemplate;
  45. import org.openspcoop2.core.plugins.IdPlugin;
  46. import org.openspcoop2.core.plugins.Plugin;
  47. import org.openspcoop2.core.plugins.PluginProprietaCompatibilita;
  48. import org.openspcoop2.core.plugins.PluginServizioAzioneCompatibilita;
  49. import org.openspcoop2.core.plugins.PluginServizioCompatibilita;
  50. import org.openspcoop2.core.plugins.dao.jdbc.converter.PluginFieldConverter;
  51. import org.openspcoop2.core.plugins.dao.jdbc.fetch.PluginFetch;
  52. import org.openspcoop2.core.plugins.utils.AliasTableRicerchePersonalizzate;
  53. import org.openspcoop2.utils.sql.ISQLQueryObject;
  54. import org.slf4j.Logger;

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

  63.     private PluginFieldConverter _pluginFieldConverter = null;
  64.     public PluginFieldConverter getPluginFieldConverter() {
  65.         if(this._pluginFieldConverter==null){
  66.             this._pluginFieldConverter = new PluginFieldConverter(this.jdbcServiceManager.getJdbcProperties().getDatabaseType());
  67.         }      
  68.         return this._pluginFieldConverter;
  69.     }
  70.     @Override
  71.     public ISQLFieldConverter getFieldConverter() {
  72.         return this.getPluginFieldConverter();
  73.     }
  74.    
  75.     private PluginFetch pluginFetch = new PluginFetch();
  76.     public PluginFetch getPluginFetch() {
  77.         return this.pluginFetch;
  78.     }
  79.     @Override
  80.     public IJDBCFetch getFetch() {
  81.         return getPluginFetch();
  82.     }
  83.    
  84.    
  85.     private JDBCServiceManager jdbcServiceManager = null;

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

  96.     @Override
  97.     public IdPlugin convertToId(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, Plugin plugin) throws NotImplementedException, ServiceException, Exception{
  98.    
  99.         IdPlugin idPlugin = new IdPlugin();
  100.         idPlugin.setTipoPlugin(plugin.getTipoPlugin());
  101.         idPlugin.setTipo(plugin.getTipo());
  102.         idPlugin.setClassName(plugin.getClassName());
  103.         idPlugin.setLabel(plugin.getLabel());
  104.         return idPlugin;
  105.     }
  106.    
  107.     @Override
  108.     public Plugin get(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdPlugin id, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotFoundException, MultipleResultException, NotImplementedException, ServiceException,Exception {
  109.         Long id_plugin = ( (id!=null && id.getId()!=null && id.getId()>0) ? id.getId() : this.findIdPlugin(jdbcProperties, log, connection, sqlQueryObject, id, true));
  110.         return this.getEngine(jdbcProperties, log, connection, sqlQueryObject, id_plugin,idMappingResolutionBehaviour);
  111.        
  112.        
  113.     }
  114.    
  115.     @Override
  116.     public boolean exists(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdPlugin id) throws MultipleResultException, NotImplementedException, ServiceException,Exception {

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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



  366.     // -- ConstructorExpression

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


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

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

  404.     @Override
  405.     public void mappingTableIds(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdPlugin id, Plugin obj) throws NotFoundException,NotImplementedException,ServiceException,Exception{
  406.         _mappingTableIds(jdbcProperties,log,connection,sqlQueryObject,obj,
  407.                 this.get(jdbcProperties,log,connection,sqlQueryObject,id,null));
  408.     }
  409.    
  410.     @Override
  411.     public void mappingTableIds(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId, Plugin obj) throws NotFoundException,NotImplementedException,ServiceException,Exception{
  412.         _mappingTableIds(jdbcProperties,log,connection,sqlQueryObject,obj,
  413.                 this.get(jdbcProperties,log,connection,sqlQueryObject,tableId,null));
  414.     }
  415.     private void _mappingTableIds(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, Plugin obj, Plugin imgSaved) throws NotFoundException,NotImplementedException,ServiceException,Exception{
  416.         if(imgSaved==null){
  417.             return;
  418.         }
  419.         obj.setId(imgSaved.getId());
  420.         if(obj.getPluginServizioCompatibilitaList()!=null){
  421.             List<org.openspcoop2.core.plugins.PluginServizioCompatibilita> listObj_ = obj.getPluginServizioCompatibilitaList();
  422.             for(org.openspcoop2.core.plugins.PluginServizioCompatibilita itemObj_ : listObj_){
  423.                 org.openspcoop2.core.plugins.PluginServizioCompatibilita itemAlreadySaved_ = null;
  424.                 if(imgSaved.getPluginServizioCompatibilitaList()!=null){
  425.                     List<org.openspcoop2.core.plugins.PluginServizioCompatibilita> listImgSaved_ = imgSaved.getPluginServizioCompatibilitaList();
  426.                     for(org.openspcoop2.core.plugins.PluginServizioCompatibilita itemImgSaved_ : listImgSaved_){
  427.                         boolean objEqualsToImgSaved_ = false;
  428.                         objEqualsToImgSaved_ = org.openspcoop2.generic_project.utils.Utilities.equals(itemObj_.getUriAccordo(),itemImgSaved_.getUriAccordo()) &&
  429.                                                 org.openspcoop2.generic_project.utils.Utilities.equals(itemObj_.getServizio(),itemImgSaved_.getServizio());
  430.                         if(objEqualsToImgSaved_){
  431.                             itemAlreadySaved_=itemImgSaved_;
  432.                             break;
  433.                         }
  434.                     }
  435.                 }
  436.                 if(itemAlreadySaved_!=null){
  437.                     itemObj_.setId(itemAlreadySaved_.getId());
  438.                     if(itemObj_.getPluginServizioAzioneCompatibilitaList()!=null){
  439.                         List<org.openspcoop2.core.plugins.PluginServizioAzioneCompatibilita> listObj_pluginServizioCompatibilita = itemObj_.getPluginServizioAzioneCompatibilitaList();
  440.                         for(org.openspcoop2.core.plugins.PluginServizioAzioneCompatibilita itemObj_pluginServizioCompatibilita : listObj_pluginServizioCompatibilita){
  441.                             org.openspcoop2.core.plugins.PluginServizioAzioneCompatibilita itemAlreadySaved_pluginServizioCompatibilita = null;
  442.                             if(itemAlreadySaved_.getPluginServizioAzioneCompatibilitaList()!=null){
  443.                                 List<org.openspcoop2.core.plugins.PluginServizioAzioneCompatibilita> listImgSaved_pluginServizioCompatibilita = itemAlreadySaved_.getPluginServizioAzioneCompatibilitaList();
  444.                                 for(org.openspcoop2.core.plugins.PluginServizioAzioneCompatibilita itemImgSaved_pluginServizioCompatibilita : listImgSaved_pluginServizioCompatibilita){
  445.                                     boolean objEqualsToImgSaved_pluginServizioCompatibilita = false;
  446.                                     objEqualsToImgSaved_pluginServizioCompatibilita = org.openspcoop2.generic_project.utils.Utilities.equals(itemObj_pluginServizioCompatibilita.getAzione(),itemImgSaved_pluginServizioCompatibilita.getAzione());
  447.                                     if(objEqualsToImgSaved_pluginServizioCompatibilita){
  448.                                         itemAlreadySaved_pluginServizioCompatibilita=itemImgSaved_pluginServizioCompatibilita;
  449.                                         break;
  450.                                     }
  451.                                 }
  452.                             }
  453.                             if(itemAlreadySaved_pluginServizioCompatibilita!=null){
  454.                                 itemObj_pluginServizioCompatibilita.setId(itemAlreadySaved_pluginServizioCompatibilita.getId());
  455.                             }
  456.                         }
  457.                     }
  458.                 }
  459.             }
  460.         }
  461.         if(obj.getPluginProprietaCompatibilitaList()!=null){
  462.             List<org.openspcoop2.core.plugins.PluginProprietaCompatibilita> listObj_ = obj.getPluginProprietaCompatibilitaList();
  463.             for(org.openspcoop2.core.plugins.PluginProprietaCompatibilita itemObj_ : listObj_){
  464.                 org.openspcoop2.core.plugins.PluginProprietaCompatibilita itemAlreadySaved_ = null;
  465.                 if(imgSaved.getPluginProprietaCompatibilitaList()!=null){
  466.                     List<org.openspcoop2.core.plugins.PluginProprietaCompatibilita> listImgSaved_ = imgSaved.getPluginProprietaCompatibilitaList();
  467.                     for(org.openspcoop2.core.plugins.PluginProprietaCompatibilita itemImgSaved_ : listImgSaved_){
  468.                         boolean objEqualsToImgSaved_ = false;
  469.                         objEqualsToImgSaved_ = org.openspcoop2.generic_project.utils.Utilities.equals(itemObj_.getNome(),itemImgSaved_.getNome());
  470.                         if(objEqualsToImgSaved_){
  471.                             itemAlreadySaved_=itemImgSaved_;
  472.                             break;
  473.                         }
  474.                     }
  475.                 }
  476.                 if(itemAlreadySaved_!=null){
  477.                     itemObj_.setId(itemAlreadySaved_.getId());
  478.                 }
  479.             }
  480.         }        
  481.     }
  482.    
  483.     @Override
  484.     public Plugin get(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotFoundException, MultipleResultException, NotImplementedException, ServiceException, Exception {
  485.         return this.getEngine(jdbcProperties, log, connection, sqlQueryObject, Long.valueOf(tableId), idMappingResolutionBehaviour);
  486.     }
  487.    
  488.     private Plugin getEngine(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, Long tableId, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotFoundException, MultipleResultException, NotImplementedException, ServiceException, Exception {
  489.    
  490.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  491.                     new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);
  492.        
  493.         ISQLQueryObject sqlQueryObjectGet = sqlQueryObject.newSQLQueryObject();
  494.                
  495.         Plugin plugin = new Plugin();
  496.        

  497.         // Object plugin
  498.         ISQLQueryObject sqlQueryObjectGet_plugin = sqlQueryObjectGet.newSQLQueryObject();
  499.         sqlQueryObjectGet_plugin.setANDLogicOperator(true);
  500.         sqlQueryObjectGet_plugin.addFromTable(this.getPluginFieldConverter().toTable(Plugin.model()));
  501.         sqlQueryObjectGet_plugin.addSelectField("id");
  502.         sqlQueryObjectGet_plugin.addSelectField(this.getPluginFieldConverter().toColumn(Plugin.model().TIPO_PLUGIN,true));
  503.         sqlQueryObjectGet_plugin.addSelectField(this.getPluginFieldConverter().toColumn(Plugin.model().CLASS_NAME,true));
  504.         sqlQueryObjectGet_plugin.addSelectField(this.getPluginFieldConverter().toColumn(Plugin.model().TIPO,true));
  505.         sqlQueryObjectGet_plugin.addSelectField(this.getPluginFieldConverter().toColumn(Plugin.model().DESCRIZIONE,true));
  506.         sqlQueryObjectGet_plugin.addSelectField(this.getPluginFieldConverter().toColumn(Plugin.model().LABEL,true));
  507.         sqlQueryObjectGet_plugin.addSelectField(this.getPluginFieldConverter().toColumn(Plugin.model().STATO,true));
  508.         sqlQueryObjectGet_plugin.addWhereCondition("id=?");

  509.         // Get plugin
  510.         plugin = (Plugin) jdbcUtilities.executeQuerySingleResult(sqlQueryObjectGet_plugin.createSQLQuery(), jdbcProperties.isShowSql(), Plugin.model(), this.getPluginFetch(),
  511.             new JDBCObject(tableId,Long.class));



  512.         // Object plugin_pluginServizioCompatibilita
  513.         ISQLQueryObject sqlQueryObjectGet_plugin_pluginServizioCompatibilita = sqlQueryObjectGet.newSQLQueryObject();
  514.         sqlQueryObjectGet_plugin_pluginServizioCompatibilita.setANDLogicOperator(true);
  515.         sqlQueryObjectGet_plugin_pluginServizioCompatibilita.addFromTable(this.getPluginFieldConverter().toTable(Plugin.model().PLUGIN_SERVIZIO_COMPATIBILITA));
  516.         sqlQueryObjectGet_plugin_pluginServizioCompatibilita.addSelectField("id");
  517.         sqlQueryObjectGet_plugin_pluginServizioCompatibilita.addSelectField(this.getPluginFieldConverter().toColumn(Plugin.model().PLUGIN_SERVIZIO_COMPATIBILITA.URI_ACCORDO,true));
  518.         sqlQueryObjectGet_plugin_pluginServizioCompatibilita.addSelectField(this.getPluginFieldConverter().toColumn(Plugin.model().PLUGIN_SERVIZIO_COMPATIBILITA.SERVIZIO,true));
  519.         sqlQueryObjectGet_plugin_pluginServizioCompatibilita.addWhereCondition("id_plugin=?");

  520.         // Get plugin_pluginServizioCompatibilita
  521.         java.util.List<Object> plugin_pluginServizioCompatibilita_list = jdbcUtilities.executeQuery(sqlQueryObjectGet_plugin_pluginServizioCompatibilita.createSQLQuery(), jdbcProperties.isShowSql(), Plugin.model().PLUGIN_SERVIZIO_COMPATIBILITA, this.getPluginFetch(),
  522.             new JDBCObject(plugin.getId(),Long.class));

  523.         if(plugin_pluginServizioCompatibilita_list != null) {
  524.             for (Object plugin_pluginServizioCompatibilita_object: plugin_pluginServizioCompatibilita_list) {
  525.                 PluginServizioCompatibilita plugin_pluginServizioCompatibilita = (PluginServizioCompatibilita) plugin_pluginServizioCompatibilita_object;



  526.                 // Object plugin_pluginServizioCompatibilita_pluginServizioAzioneCompatibilita
  527.                 ISQLQueryObject sqlQueryObjectGet_plugin_pluginServizioCompatibilita_pluginServizioAzioneCompatibilita = sqlQueryObjectGet.newSQLQueryObject();
  528.                 sqlQueryObjectGet_plugin_pluginServizioCompatibilita_pluginServizioAzioneCompatibilita.setANDLogicOperator(true);
  529.                 sqlQueryObjectGet_plugin_pluginServizioCompatibilita_pluginServizioAzioneCompatibilita.addFromTable(this.getPluginFieldConverter().toTable(Plugin.model().PLUGIN_SERVIZIO_COMPATIBILITA.PLUGIN_SERVIZIO_AZIONE_COMPATIBILITA));
  530.                 sqlQueryObjectGet_plugin_pluginServizioCompatibilita_pluginServizioAzioneCompatibilita.addSelectField("id");
  531.                 sqlQueryObjectGet_plugin_pluginServizioCompatibilita_pluginServizioAzioneCompatibilita.addSelectField(this.getPluginFieldConverter().toColumn(Plugin.model().PLUGIN_SERVIZIO_COMPATIBILITA.PLUGIN_SERVIZIO_AZIONE_COMPATIBILITA.AZIONE,true));
  532.                 sqlQueryObjectGet_plugin_pluginServizioCompatibilita_pluginServizioAzioneCompatibilita.addWhereCondition("id_plugin_servizio_comp=?");

  533.                 // Get plugin_pluginServizioCompatibilita_pluginServizioAzioneCompatibilita
  534.                 java.util.List<Object> plugin_pluginServizioCompatibilita_pluginServizioAzioneCompatibilita_list = jdbcUtilities.executeQuery(sqlQueryObjectGet_plugin_pluginServizioCompatibilita_pluginServizioAzioneCompatibilita.createSQLQuery(), jdbcProperties.isShowSql(), Plugin.model().PLUGIN_SERVIZIO_COMPATIBILITA.PLUGIN_SERVIZIO_AZIONE_COMPATIBILITA, this.getPluginFetch(),
  535.                     new JDBCObject(plugin_pluginServizioCompatibilita.getId(),Long.class));

  536.                 if(plugin_pluginServizioCompatibilita_pluginServizioAzioneCompatibilita_list != null) {
  537.                     for (Object plugin_pluginServizioCompatibilita_pluginServizioAzioneCompatibilita_object: plugin_pluginServizioCompatibilita_pluginServizioAzioneCompatibilita_list) {
  538.                         PluginServizioAzioneCompatibilita plugin_pluginServizioCompatibilita_pluginServizioAzioneCompatibilita = (PluginServizioAzioneCompatibilita) plugin_pluginServizioCompatibilita_pluginServizioAzioneCompatibilita_object;


  539.                         plugin_pluginServizioCompatibilita.addPluginServizioAzioneCompatibilita(plugin_pluginServizioCompatibilita_pluginServizioAzioneCompatibilita);
  540.                     }
  541.                 }
  542.                 plugin.addPluginServizioCompatibilita(plugin_pluginServizioCompatibilita);
  543.             }
  544.         }

  545.         // Object plugin_pluginProprietaCompatibilita
  546.         ISQLQueryObject sqlQueryObjectGet_plugin_pluginProprietaCompatibilita = sqlQueryObjectGet.newSQLQueryObject();
  547.         sqlQueryObjectGet_plugin_pluginProprietaCompatibilita.setANDLogicOperator(true);
  548.         sqlQueryObjectGet_plugin_pluginProprietaCompatibilita.addFromTable(this.getPluginFieldConverter().toTable(Plugin.model().PLUGIN_PROPRIETA_COMPATIBILITA));
  549.         sqlQueryObjectGet_plugin_pluginProprietaCompatibilita.addSelectField("id");
  550.         sqlQueryObjectGet_plugin_pluginProprietaCompatibilita.addSelectField(this.getPluginFieldConverter().toColumn(Plugin.model().PLUGIN_PROPRIETA_COMPATIBILITA.NOME,true));
  551.         sqlQueryObjectGet_plugin_pluginProprietaCompatibilita.addSelectField(this.getPluginFieldConverter().toColumn(Plugin.model().PLUGIN_PROPRIETA_COMPATIBILITA.VALORE,true));
  552.         sqlQueryObjectGet_plugin_pluginProprietaCompatibilita.addWhereCondition("id_plugin=?");

  553.         // Get plugin_pluginProprietaCompatibilita
  554.         java.util.List<Object> plugin_pluginProprietaCompatibilita_list = (java.util.List<Object>) jdbcUtilities.executeQuery(sqlQueryObjectGet_plugin_pluginProprietaCompatibilita.createSQLQuery(), jdbcProperties.isShowSql(), Plugin.model().PLUGIN_PROPRIETA_COMPATIBILITA, this.getPluginFetch(),
  555.             new JDBCObject(plugin.getId(),Long.class));

  556.         if(plugin_pluginProprietaCompatibilita_list != null) {
  557.             for (Object plugin_pluginProprietaCompatibilita_object: plugin_pluginProprietaCompatibilita_list) {
  558.                 PluginProprietaCompatibilita plugin_pluginProprietaCompatibilita = (PluginProprietaCompatibilita) plugin_pluginProprietaCompatibilita_object;


  559.                 plugin.addPluginProprietaCompatibilita(plugin_pluginProprietaCompatibilita);
  560.             }
  561.         }

  562.        
  563.         return plugin;  
  564.    
  565.     }
  566.    
  567.     @Override
  568.     public boolean exists(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId) throws MultipleResultException, NotImplementedException, ServiceException, Exception {
  569.         return this._exists(jdbcProperties, log, connection, sqlQueryObject, Long.valueOf(tableId));
  570.     }
  571.    
  572.     private boolean _exists(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, Long tableId) throws MultipleResultException, NotImplementedException, ServiceException, Exception {
  573.    
  574.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  575.                     new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);
  576.                
  577.         boolean existsPlugin = false;

  578.         sqlQueryObject = sqlQueryObject.newSQLQueryObject();
  579.         sqlQueryObject.setANDLogicOperator(true);

  580.         sqlQueryObject.addFromTable(this.getPluginFieldConverter().toTable(Plugin.model()));
  581.         sqlQueryObject.addSelectField(this.getPluginFieldConverter().toColumn(Plugin.model().TIPO_PLUGIN,true));
  582.         sqlQueryObject.addWhereCondition("id=?");


  583.         // Exists plugin
  584.         existsPlugin = jdbcUtilities.exists(sqlQueryObject.createSQLQuery(), jdbcProperties.isShowSql(),
  585.             new JDBCObject(tableId,Long.class));

  586.        
  587.         return existsPlugin;
  588.    
  589.     }
  590.    
  591.     private void joinEngine(IExpression expression, ISQLQueryObject sqlQueryObject) throws NotImplementedException, ServiceException, Exception{
  592.    
  593.         if(expression.inUseModel(Plugin.model().PLUGIN_SERVIZIO_COMPATIBILITA,false)){
  594.             String tableName1 = this.getPluginFieldConverter().toAliasTable(Plugin.model());
  595.             String tableName2 = this.getPluginFieldConverter().toAliasTable(Plugin.model().PLUGIN_SERVIZIO_COMPATIBILITA);
  596.             sqlQueryObject.addWhereCondition(tableName1+".id="+tableName2+".id_plugin");
  597.         }
  598.         if(expression.inUseModel(Plugin.model().PLUGIN_SERVIZIO_COMPATIBILITA.PLUGIN_SERVIZIO_AZIONE_COMPATIBILITA,false)){
  599.             String tableName1 = this.getPluginFieldConverter().toAliasTable(Plugin.model().PLUGIN_SERVIZIO_COMPATIBILITA);
  600.             String tableName2 = this.getPluginFieldConverter().toAliasTable(Plugin.model().PLUGIN_SERVIZIO_COMPATIBILITA.PLUGIN_SERVIZIO_AZIONE_COMPATIBILITA);
  601.             sqlQueryObject.addWhereCondition(tableName1+".id="+tableName2+".id_plugin_servizio_comp");
  602.         }
  603.        
  604.         if(expression.inUseModel(Plugin.model().PLUGIN_SERVIZIO_COMPATIBILITA.PLUGIN_SERVIZIO_AZIONE_COMPATIBILITA,false)){
  605.             if(expression.inUseModel(Plugin.model().PLUGIN_SERVIZIO_COMPATIBILITA,false)==false){
  606.                 sqlQueryObject.addFromTable(this.getPluginFieldConverter().toTable(Plugin.model().PLUGIN_SERVIZIO_COMPATIBILITA));
  607.             }
  608.         }
  609.        
  610.         AliasTableRicerchePersonalizzate.join(expression, sqlQueryObject, Plugin.model(),
  611.                 Plugin.model().PLUGIN_PROPRIETA_COMPATIBILITA, this.getFieldConverter());
  612.        
  613.     }
  614.    
  615.     protected java.util.List<Object> getRootTablePrimaryKeyValuesEngine(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdPlugin id) throws NotFoundException, ServiceException, NotImplementedException, Exception{
  616.         // Identificativi
  617.         java.util.List<Object> rootTableIdValues = new java.util.ArrayList<>();
  618.         Long longId = this.findIdPlugin(jdbcProperties, log, connection, sqlQueryObject.newSQLQueryObject(), id, true);
  619.         rootTableIdValues.add(longId);
  620.        
  621.         return rootTableIdValues;
  622.     }
  623.    
  624.     protected Map<String, List<IField>> getMapTableToPKColumnEngine() throws NotImplementedException, Exception{
  625.    
  626.         PluginFieldConverter converter = this.getPluginFieldConverter();
  627.         Map<String, List<IField>> mapTableToPKColumn = new java.util.HashMap<>();
  628.         UtilsTemplate<IField> utilities = new UtilsTemplate<>();

  629.         // Plugin.model()
  630.         mapTableToPKColumn.put(converter.toTable(Plugin.model()),
  631.             utilities.newList(
  632.                 new CustomField("id", Long.class, "id", converter.toTable(Plugin.model()))
  633.             ));

  634.         // Plugin.model().PLUGIN_SERVIZIO_COMPATIBILITA
  635.         mapTableToPKColumn.put(converter.toTable(Plugin.model().PLUGIN_SERVIZIO_COMPATIBILITA),
  636.             utilities.newList(
  637.                 new CustomField("id", Long.class, "id", converter.toTable(Plugin.model().PLUGIN_SERVIZIO_COMPATIBILITA))
  638.             ));

  639.         // Plugin.model().PLUGIN_SERVIZIO_COMPATIBILITA.PLUGIN_SERVIZIO_AZIONE_COMPATIBILITA
  640.         mapTableToPKColumn.put(converter.toTable(Plugin.model().PLUGIN_SERVIZIO_COMPATIBILITA.PLUGIN_SERVIZIO_AZIONE_COMPATIBILITA),
  641.             utilities.newList(
  642.                 new CustomField("id", Long.class, "id", converter.toTable(Plugin.model().PLUGIN_SERVIZIO_COMPATIBILITA.PLUGIN_SERVIZIO_AZIONE_COMPATIBILITA))
  643.             ));

  644.         // Plugin.model().PLUGIN_PROPRIETA_COMPATIBILITA
  645.         mapTableToPKColumn.put(converter.toTable(Plugin.model().PLUGIN_PROPRIETA_COMPATIBILITA),
  646.             utilities.newList(
  647.                 new CustomField("id", Long.class, "id", converter.toTable(Plugin.model().PLUGIN_PROPRIETA_COMPATIBILITA))
  648.             ));
  649.        
  650.         return mapTableToPKColumn;      
  651.     }
  652.    
  653.     @Override
  654.     public List<Long> findAllTableIds(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCPaginatedExpression paginatedExpression) throws ServiceException, NotImplementedException, Exception {
  655.        
  656.         List<Long> list = new ArrayList<Long>();

  657.         sqlQueryObject.setSelectDistinct(true);
  658.         sqlQueryObject.setANDLogicOperator(true);
  659.         sqlQueryObject.addSelectField(this.getPluginFieldConverter().toTable(Plugin.model())+".id");
  660.         Class<?> objectIdClass = Long.class;
  661.        
  662.         List<Object> listaQuery = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareFindAll(jdbcProperties, log, connection, sqlQueryObject, paginatedExpression,
  663.                                                 this.getPluginFieldConverter(), Plugin.model());
  664.        
  665.         joinEngine(paginatedExpression,sqlQueryObject);
  666.        
  667.         List<Object> listObjects = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.findAll(jdbcProperties, log, connection, sqlQueryObject, paginatedExpression,
  668.                                                                             this.getPluginFieldConverter(), Plugin.model(), objectIdClass, listaQuery);
  669.         for(Object object: listObjects) {
  670.             list.add((Long)object);
  671.         }

  672.         return list;
  673.        
  674.     }
  675.    
  676.     @Override
  677.     public long findTableId(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCExpression expression) throws ServiceException, NotFoundException, MultipleResultException, NotImplementedException, Exception {
  678.    
  679.         sqlQueryObject.setSelectDistinct(true);
  680.         sqlQueryObject.setANDLogicOperator(true);
  681.         sqlQueryObject.addSelectField(this.getPluginFieldConverter().toTable(Plugin.model())+".id");
  682.         Class<?> objectIdClass = Long.class;
  683.        
  684.         List<Object> listaQuery = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.prepareFind(jdbcProperties, log, connection, sqlQueryObject, expression,
  685.                                                 this.getPluginFieldConverter(), Plugin.model());
  686.        
  687.         joinEngine(expression,sqlQueryObject);

  688.         Object res = org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.find(jdbcProperties, log, connection, sqlQueryObject, expression,
  689.                                                         this.getPluginFieldConverter(), Plugin.model(), objectIdClass, listaQuery);
  690.         if(res!=null && (((Long) res).longValue()>0) ){
  691.             return ((Long) res).longValue();
  692.         }
  693.         else{
  694.             throw org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.newNotFoundException();
  695.         }
  696.        
  697.     }

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

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

  703.         InUse inUse = new InUse();
  704.         inUse.setInUse(false);
  705.        
  706.         /*
  707.          * TODO: implement code that checks whether the object identified by the id parameter is used by other objects
  708.         */
  709.        
  710.         // Delete this line when you have implemented the method
  711.         int throwNotImplemented = 1;
  712.         if(throwNotImplemented==1){
  713.                 throw new NotImplementedException("NotImplemented");
  714.         }
  715.         // Delete this line when you have implemented the method

  716.         return inUse;

  717.     }
  718.    
  719.     @Override
  720.     public IdPlugin findId(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId, boolean throwNotFound)
  721.             throws NotFoundException, ServiceException, NotImplementedException, Exception {
  722.        
  723.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  724.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);

  725.         ISQLQueryObject sqlQueryObjectGet = sqlQueryObject.newSQLQueryObject();              

  726.         // Object _plugin
  727.         sqlQueryObjectGet.addFromTable(this.getPluginFieldConverter().toTable(Plugin.model()));
  728.         sqlQueryObjectGet.addSelectField(this.getPluginFieldConverter().toColumn(Plugin.model().TIPO_PLUGIN,true));
  729.         sqlQueryObjectGet.addSelectField(this.getPluginFieldConverter().toColumn(Plugin.model().TIPO,true));
  730.         sqlQueryObjectGet.addSelectField(this.getPluginFieldConverter().toColumn(Plugin.model().CLASS_NAME,true));
  731.         sqlQueryObjectGet.addSelectField(this.getPluginFieldConverter().toColumn(Plugin.model().LABEL,true));
  732.         sqlQueryObjectGet.setANDLogicOperator(true);
  733.         sqlQueryObjectGet.addWhereCondition("id=?");

  734.         // Recupero _plugin
  735.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject [] searchParams_plugin = new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject [] {
  736.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(tableId,Long.class)
  737.         };
  738.         List<Class<?>> listaFieldIdReturnType_plugin = new ArrayList<Class<?>>();
  739.         listaFieldIdReturnType_plugin.add(String.class);
  740.         listaFieldIdReturnType_plugin.add(String.class);
  741.         org.openspcoop2.core.plugins.IdPlugin id_plugin = null;
  742.         List<Object> listaFieldId_plugin = jdbcUtilities.executeQuerySingleResult(sqlQueryObjectGet.createSQLQuery(), jdbcProperties.isShowSql(),
  743.                 listaFieldIdReturnType_plugin, searchParams_plugin);
  744.         if(listaFieldId_plugin==null || listaFieldId_plugin.size()<=0){
  745.             if(throwNotFound){
  746.                 throw org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.newNotFoundException();
  747.             }
  748.         }
  749.         else{
  750.             // set _plugin
  751.             id_plugin = new org.openspcoop2.core.plugins.IdPlugin();
  752.             id_plugin.setTipoPlugin((String)listaFieldId_plugin.get(0));
  753.             id_plugin.setTipo((String)listaFieldId_plugin.get(1));
  754.             id_plugin.setClassName((String)listaFieldId_plugin.get(2));
  755.             id_plugin.setLabel((String)listaFieldId_plugin.get(3));
  756.         }
  757.        
  758.         return id_plugin;
  759.        
  760.     }

  761.     @Override
  762.     public Long findTableId(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdPlugin id, boolean throwNotFound)
  763.             throws NotFoundException, ServiceException, NotImplementedException, Exception {
  764.    
  765.         return this.findIdPlugin(jdbcProperties,log,connection,sqlQueryObject,id,throwNotFound);
  766.            
  767.     }
  768.    
  769.     @Override
  770.     public List<List<Object>> nativeQuery(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject,
  771.                                             String sql,List<Class<?>> returnClassTypes,Object ... param) throws ServiceException,NotFoundException,NotImplementedException,Exception{
  772.        
  773.         return org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.nativeQuery(jdbcProperties, log, connection, sqlQueryObject,
  774.                                                                                             sql,returnClassTypes,param);
  775.                                                        
  776.     }
  777.    
  778.     protected Long findIdPlugin(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, IdPlugin id, boolean throwNotFound) throws NotFoundException, ServiceException, NotImplementedException, Exception {

  779.         if(jdbcProperties==null) {
  780.             throw new ServiceException("Param jdbcProperties is null");
  781.         }
  782.         if(sqlQueryObject==null) {
  783.             throw new ServiceException("Param sqlQueryObject is null");
  784.         }
  785.         if(id==null) {
  786.             throw new ServiceException("Param id is null");
  787.         }
  788.        
  789.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  790.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);

  791.         ISQLQueryObject sqlQueryObjectGet = sqlQueryObject.newSQLQueryObject();

  792.         if(id.getTipoPlugin()==null) {
  793.             throw new ServiceException("Nell'identificativo di plugin deve essere fornito il tipo di plugin");
  794.         }
  795.        
  796.         // Object _plugin
  797.         sqlQueryObjectGet.addFromTable(this.getPluginFieldConverter().toTable(Plugin.model()));
  798.         sqlQueryObjectGet.addSelectField("id");
  799.         // Devono essere mappati nella where condition i metodi dell'oggetto id.getXXX
  800.         sqlQueryObjectGet.setANDLogicOperator(true);
  801.         sqlQueryObjectGet.setSelectDistinct(true);
  802.         sqlQueryObjectGet.addWhereCondition(this.getPluginFieldConverter().toColumn(Plugin.model().TIPO_PLUGIN,true)+"=?");
  803.         String valore = null;
  804.         if(id.getTipo()!=null) {
  805.             sqlQueryObjectGet.addWhereCondition(this.getPluginFieldConverter().toColumn(Plugin.model().TIPO,true)+"=?");
  806.             valore = id.getTipo();
  807.         }
  808.         else if(id.getClassName()!=null) {
  809.             sqlQueryObjectGet.addWhereCondition(this.getPluginFieldConverter().toColumn(Plugin.model().CLASS_NAME,true)+"=?");
  810.             valore = id.getClassName();
  811.         }
  812.         else {
  813.             throw new ServiceException("Nell'identificativo di plugin deve essere fornito almeno un tipo o un class name");
  814.         }

  815.         // Recupero _plugin
  816.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject [] searchParams_plugin = new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject [] {
  817.                 new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(id.getTipoPlugin(),String.class),
  818.                 new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(valore,String.class)
  819.         };
  820.         Long id_plugin = null;
  821.         try{
  822.             id_plugin = (Long) jdbcUtilities.executeQuerySingleResult(sqlQueryObjectGet.createSQLQuery(), jdbcProperties.isShowSql(),
  823.                         Long.class, searchParams_plugin);
  824.         }catch(NotFoundException notFound){
  825.             if(throwNotFound){
  826.                 throw new NotFoundException(notFound);
  827.             }
  828.         }
  829.         if(id_plugin==null || id_plugin<=0){
  830.             if(throwNotFound){
  831.                 throw org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.newNotFoundException();
  832.             }
  833.         }
  834.        
  835.         return id_plugin;
  836.     }
  837. }