JDBCTransazioneInfoServiceImpl.java

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

  21. import java.sql.Connection;

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

  23. import org.slf4j.Logger;

  24. import org.openspcoop2.generic_project.dao.jdbc.IJDBCServiceCRUDWithoutId;
  25. import org.openspcoop2.generic_project.beans.NonNegativeNumber;
  26. import org.openspcoop2.generic_project.beans.UpdateField;
  27. import org.openspcoop2.generic_project.beans.UpdateModel;

  28. import org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities;
  29. import org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject;
  30. import org.openspcoop2.generic_project.exception.NotFoundException;
  31. import org.openspcoop2.generic_project.exception.NotImplementedException;
  32. import org.openspcoop2.generic_project.exception.ServiceException;
  33. import org.openspcoop2.generic_project.expression.IExpression;
  34. import org.openspcoop2.generic_project.dao.jdbc.JDBCExpression;
  35. import org.openspcoop2.generic_project.dao.jdbc.JDBCPaginatedExpression;

  36. import org.openspcoop2.generic_project.dao.jdbc.JDBCServiceManagerProperties;

  37. import org.openspcoop2.core.transazioni.TransazioneInfo;

  38. /**    
  39.  * JDBCTransazioneInfoServiceImpl
  40.  *
  41.  * @author Poli Andrea (poli@link.it)
  42.  * @author $Author$
  43.  * @version $Rev$, $Date$
  44.  */
  45. public class JDBCTransazioneInfoServiceImpl extends JDBCTransazioneInfoServiceSearchImpl
  46.     implements IJDBCServiceCRUDWithoutId<TransazioneInfo, JDBCServiceManager> {

  47.     @Override
  48.     public void create(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, TransazioneInfo transazioneInfo, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotImplementedException,ServiceException,Exception {

  49.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  50.                 new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);
  51.        
  52.         ISQLQueryObject sqlQueryObjectInsert = sqlQueryObject.newSQLQueryObject();
  53.                


  54.         // Object transazioneInfo
  55.         sqlQueryObjectInsert.addInsertTable(this.getTransazioneInfoFieldConverter().toTable(TransazioneInfo.model()));
  56.         sqlQueryObjectInsert.addInsertField(this.getTransazioneInfoFieldConverter().toColumn(TransazioneInfo.model().TIPO,false),"?");
  57.         sqlQueryObjectInsert.addInsertField(this.getTransazioneInfoFieldConverter().toColumn(TransazioneInfo.model().DATA,false),"?");

  58.         // Insert transazioneInfo
  59.         String insertSql = sqlQueryObjectInsert.createSQLInsert();
  60.         jdbcUtilities.execute(insertSql, jdbcProperties.isShowSql(),
  61.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(transazioneInfo.getTipo(),TransazioneInfo.model().TIPO.getFieldType()),
  62.             new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCObject(transazioneInfo.getData(),TransazioneInfo.model().DATA.getFieldType())
  63.         );

  64.        
  65.     }

  66.     @Override
  67.     public void update(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, TransazioneInfo transazioneInfo, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotFoundException, NotImplementedException, ServiceException, Exception {
  68.        

  69.    
  70.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  71.                 new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);
  72.        
  73.         ISQLQueryObject sqlQueryObjectInsert = sqlQueryObject.newSQLQueryObject();
  74.         ISQLQueryObject sqlQueryObjectDelete = sqlQueryObjectInsert.newSQLQueryObject();
  75.         ISQLQueryObject sqlQueryObjectGet = sqlQueryObjectDelete.newSQLQueryObject();
  76.         ISQLQueryObject sqlQueryObjectUpdate = sqlQueryObjectGet.newSQLQueryObject();
  77.        


  78.         // Object transazioneInfo
  79.         sqlQueryObjectUpdate.setANDLogicOperator(true);
  80.         sqlQueryObjectUpdate.addUpdateTable(this.getTransazioneInfoFieldConverter().toTable(TransazioneInfo.model()));
  81.         boolean isUpdate_transazioneInfo = true;
  82.         java.util.List<JDBCObject> lstObjects_transazioneInfo = new java.util.ArrayList<>();
  83.         sqlQueryObjectUpdate.addUpdateField(this.getTransazioneInfoFieldConverter().toColumn(TransazioneInfo.model().TIPO,false), "?");
  84.         lstObjects_transazioneInfo.add(new JDBCObject(transazioneInfo.getTipo(), TransazioneInfo.model().TIPO.getFieldType()));
  85.         sqlQueryObjectUpdate.addUpdateField(this.getTransazioneInfoFieldConverter().toColumn(TransazioneInfo.model().DATA,false), "?");
  86.         lstObjects_transazioneInfo.add(new JDBCObject(transazioneInfo.getData(), TransazioneInfo.model().DATA.getFieldType()));
  87.         sqlQueryObjectUpdate.addWhereCondition(this.getTransazioneInfoFieldConverter().toColumn(TransazioneInfo.model().TIPO,false)+"=?");
  88.         lstObjects_transazioneInfo.add(new JDBCObject(transazioneInfo.getTipo(), transazioneInfo.getTipo().getClass()));

  89.         if(isUpdate_transazioneInfo) {
  90.             // Update transazioneInfo
  91.             jdbcUtilities.executeUpdate(sqlQueryObjectUpdate.createSQLUpdate(), jdbcProperties.isShowSql(),
  92.                 lstObjects_transazioneInfo.toArray(new JDBCObject[]{}));
  93.         }

  94.     }
  95.     @Override
  96.     public void update(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId, TransazioneInfo transazioneInfo, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotFoundException, NotImplementedException, ServiceException, Exception {
  97.         throw new NotImplementedException("Table without long id column PK");
  98.     }
  99.    
  100.     @Override
  101.     public void updateFields(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, TransazioneInfo transazioneInfo, UpdateField ... updateFields) throws NotFoundException, NotImplementedException, ServiceException, Exception {
  102.        
  103.         GenericJDBCUtilities.updateFields(jdbcProperties, log, connection, sqlQueryObject,
  104.                 this.getTransazioneInfoFieldConverter().toTable(TransazioneInfo.model()),
  105.                 this.getMapTableToPKColumnEngine(),
  106.                 this.getRootTablePrimaryKeyValuesEngine(jdbcProperties, log, connection, sqlQueryObject, transazioneInfo),
  107.                 this.getTransazioneInfoFieldConverter(), this, null, updateFields);
  108.     }
  109.    
  110.     @Override
  111.     public void updateFields(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, TransazioneInfo transazioneInfo, IExpression condition, UpdateField ... updateFields) throws NotFoundException, NotImplementedException, ServiceException, Exception {
  112.        
  113.         GenericJDBCUtilities.updateFields(jdbcProperties, log, connection, sqlQueryObject,
  114.                 this.getTransazioneInfoFieldConverter().toTable(TransazioneInfo.model()),
  115.                 this.getMapTableToPKColumnEngine(),
  116.                 this.getRootTablePrimaryKeyValuesEngine(jdbcProperties, log, connection, sqlQueryObject, transazioneInfo),
  117.                 this.getTransazioneInfoFieldConverter(), this, condition, updateFields);
  118.     }
  119.    
  120.     @Override
  121.     public void updateFields(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, TransazioneInfo transazioneInfo, UpdateModel ... updateModels) throws NotFoundException, NotImplementedException, ServiceException, Exception {
  122.        
  123.         GenericJDBCUtilities.updateFields(jdbcProperties, log, connection, sqlQueryObject,
  124.                 this.getTransazioneInfoFieldConverter().toTable(TransazioneInfo.model()),
  125.                 this.getMapTableToPKColumnEngine(),
  126.                 this.getRootTablePrimaryKeyValuesEngine(jdbcProperties, log, connection, sqlQueryObject, transazioneInfo),
  127.                 this.getTransazioneInfoFieldConverter(), this, updateModels);
  128.     }  
  129.    
  130.     @Override
  131.     public void updateFields(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId, UpdateField ... updateFields) throws NotFoundException, NotImplementedException, ServiceException, Exception {
  132.         throw new NotImplementedException("Table without long id column PK");
  133.     }
  134.    
  135.     @Override
  136.     public void updateFields(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId, IExpression condition, UpdateField ... updateFields) throws NotFoundException, NotImplementedException, ServiceException, Exception {
  137.         throw new NotImplementedException("Table without long id column PK");
  138.     }
  139.    
  140.     @Override
  141.     public void updateFields(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId, UpdateModel ... updateModels) throws NotFoundException, NotImplementedException, ServiceException, Exception {
  142.         throw new NotImplementedException("Table without long id column PK");
  143.     }
  144.    
  145.     @Override
  146.     public void updateOrCreate(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, TransazioneInfo transazioneInfo, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotImplementedException,ServiceException,Exception {
  147.    
  148.         Object idObject = transazioneInfo.getTipo();
  149.         if(this._exists(jdbcProperties, log, connection, sqlQueryObject, idObject)) {
  150.             this.update(jdbcProperties, log, connection, sqlQueryObject, transazioneInfo,idMappingResolutionBehaviour);
  151.         } else {
  152.             this.create(jdbcProperties, log, connection, sqlQueryObject, transazioneInfo,idMappingResolutionBehaviour);
  153.         }
  154.        
  155.     }
  156.    
  157.     @Override
  158.     public void updateOrCreate(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId, TransazioneInfo transazioneInfo, org.openspcoop2.generic_project.beans.IDMappingBehaviour idMappingResolutionBehaviour) throws NotImplementedException,ServiceException,Exception {
  159.         throw new NotImplementedException("Table without long id column PK");
  160.     }
  161.    
  162.     @Override
  163.     public void delete(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, TransazioneInfo transazioneInfo) throws NotImplementedException,ServiceException,Exception {
  164.        
  165.        
  166.         Object idObject = transazioneInfo.getTipo();
  167.         this.deleteEngine(jdbcProperties, log, connection, sqlQueryObject, idObject);

  168.        
  169.     }

  170.     private void deleteEngine(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, Object id) throws NotImplementedException,ServiceException,Exception {
  171.        
  172.         org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities jdbcUtilities =
  173.                 new org.openspcoop2.generic_project.dao.jdbc.utils.JDBCPreparedStatementUtilities(sqlQueryObject.getTipoDatabaseOpenSPCoop2(), log, connection);
  174.        
  175.         ISQLQueryObject sqlQueryObjectDelete = sqlQueryObject.newSQLQueryObject();
  176.        

  177.         // Object transazioneInfo
  178.         sqlQueryObjectDelete.setANDLogicOperator(true);
  179.         sqlQueryObjectDelete.addDeleteTable(this.getTransazioneInfoFieldConverter().toTable(TransazioneInfo.model()));
  180.         sqlQueryObjectDelete.addWhereCondition(this.getTransazioneInfoFieldConverter().toColumn(TransazioneInfo.model().TIPO,false)+"=?");

  181.         // Delete transazioneInfo
  182.         jdbcUtilities.execute(sqlQueryObjectDelete.createSQLDelete(), jdbcProperties.isShowSql(),
  183.             new JDBCObject(id,id.getClass()));

  184.     }

  185.    
  186.     @Override
  187.     public NonNegativeNumber deleteAll(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject) throws NotImplementedException,ServiceException,Exception {
  188.        
  189.         return this.deleteAll(jdbcProperties, log, connection, sqlQueryObject, new JDBCExpression(this.getTransazioneInfoFieldConverter()));

  190.     }

  191.     @Override
  192.     public NonNegativeNumber deleteAll(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, JDBCExpression expression) throws NotImplementedException, ServiceException,Exception {

  193.         java.util.List<Object> lst = this._findAllObjectIds(jdbcProperties, log, connection, sqlQueryObject, new JDBCPaginatedExpression(expression));
  194.        
  195.         for(Object id : lst) {
  196.             this.deleteEngine(jdbcProperties, log, connection, sqlQueryObject, id);
  197.         }
  198.        
  199.         return new NonNegativeNumber(lst.size());
  200.    
  201.     }



  202.     // -- DB
  203.    
  204.     @Override
  205.     public void deleteById(JDBCServiceManagerProperties jdbcProperties, Logger log, Connection connection, ISQLQueryObject sqlQueryObject, long tableId) throws ServiceException, NotImplementedException, Exception {
  206.         throw new NotImplementedException("Table without long id column PK");
  207.     }
  208.    
  209.     @Override
  210.     public int nativeUpdate(JDBCServiceManagerProperties jdbcProperties, Logger log,Connection connection,ISQLQueryObject sqlObject, String sql,Object ... param) throws ServiceException,NotImplementedException, Exception {
  211.    
  212.         return org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCUtilities.nativeUpdate(jdbcProperties, log, connection, sqlObject,
  213.                                                                                             sql,param);
  214.    
  215.     }
  216. }