TransazioneInfoFieldConverter.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.converter;

  21. import org.openspcoop2.generic_project.beans.IField;
  22. import org.openspcoop2.generic_project.beans.IModel;
  23. import org.openspcoop2.generic_project.exception.ExpressionException;
  24. import org.openspcoop2.generic_project.expression.impl.sql.AbstractSQLFieldConverter;
  25. import org.openspcoop2.utils.TipiDatabase;

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


  27. /**    
  28.  * TransazioneInfoFieldConverter
  29.  *
  30.  * @author Poli Andrea (poli@link.it)
  31.  * @author $Author$
  32.  * @version $Rev$, $Date$
  33.  */
  34. public class TransazioneInfoFieldConverter extends AbstractSQLFieldConverter {

  35.     private TipiDatabase databaseType;
  36.    
  37.     public TransazioneInfoFieldConverter(String databaseType){
  38.         this.databaseType = TipiDatabase.toEnumConstant(databaseType);
  39.     }
  40.     public TransazioneInfoFieldConverter(TipiDatabase databaseType){
  41.         this.databaseType = databaseType;
  42.     }


  43.     @Override
  44.     public IModel<?> getRootModel() throws ExpressionException {
  45.         return TransazioneInfo.model();
  46.     }
  47.    
  48.     @Override
  49.     public TipiDatabase getDatabaseType() throws ExpressionException {
  50.         return this.databaseType;
  51.     }
  52.    


  53.     @Override
  54.     public String toColumn(IField field,boolean returnAlias,boolean appendTablePrefix) throws ExpressionException {
  55.        
  56.         // In the case of columns with alias, using parameter returnAlias​​,
  57.         // it is possible to drive the choice whether to return only the alias or
  58.         // the full definition of the column containing the alias
  59.        
  60.         if(field.equals(TransazioneInfo.model().TIPO)){
  61.             if(appendTablePrefix){
  62.                 return this.toAliasTable(field)+".tipo";
  63.             }else{
  64.                 return "tipo";
  65.             }
  66.         }
  67.         if(field.equals(TransazioneInfo.model().DATA)){
  68.             if(appendTablePrefix){
  69.                 return this.toAliasTable(field)+".data";
  70.             }else{
  71.                 return "data";
  72.             }
  73.         }


  74.         return super.toColumn(field,returnAlias,appendTablePrefix);
  75.        
  76.     }
  77.    
  78.     @Override
  79.     public String toTable(IField field,boolean returnAlias) throws ExpressionException {
  80.        
  81.         // In the case of table with alias, using parameter returnAlias​​,
  82.         // it is possible to drive the choice whether to return only the alias or
  83.         // the full definition of the table containing the alias
  84.        
  85.         if(field.equals(TransazioneInfo.model().TIPO)){
  86.             return this.toTable(TransazioneInfo.model(), returnAlias);
  87.         }
  88.         if(field.equals(TransazioneInfo.model().DATA)){
  89.             return this.toTable(TransazioneInfo.model(), returnAlias);
  90.         }


  91.         return super.toTable(field,returnAlias);
  92.        
  93.     }

  94.     @Override
  95.     public String toTable(IModel<?> model,boolean returnAlias) throws ExpressionException {
  96.        
  97.         // In the case of table with alias, using parameter returnAlias​​,
  98.         // it is possible to drive the choice whether to return only the alias or
  99.         // the full definition of the table containing the alias
  100.        
  101.         if(model.equals(TransazioneInfo.model())){
  102.             return "transazioni_info";
  103.         }


  104.         return super.toTable(model,returnAlias);
  105.        
  106.     }

  107. }