BlobJDBCAdapter.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.utils.jdbc;

  21. import java.io.InputStream;
  22. import java.sql.Blob;
  23. import java.sql.ResultSet;
  24. import java.sql.SQLException;

  25. import org.openspcoop2.utils.TipiDatabase;
  26. import org.openspcoop2.utils.UtilsException;

  27. /**
  28.  * Implementazione dell'interfaccia JDBCAdapter
  29.  * che definisce un adapter JDBC per la gestione del repository del messaggi
  30.  *
  31.  * @author Poli Andrea (apoli@link.it)
  32.  * @author $Author$
  33.  * @version $Rev$, $Date$
  34.  */

  35. public class BlobJDBCAdapter extends AbstractJDBCAdapter {

  36.    
  37.     public BlobJDBCAdapter(TipiDatabase tipoDatabase) {
  38.         super(tipoDatabase);
  39.     }

  40.    
  41.    
  42.     /* ***** BYTES ****** */

  43.     /**
  44.      * Si occupa di ottenere il messaggio precedentemente salvato sul DB,
  45.      * effettuando una get all'indice <var>index</var>.
  46.      *
  47.      * @param rs ResultSet da utilizzare.
  48.      * @param index Indice su cui prelevare il messaggio
  49.      *
  50.      */
  51.     @Override
  52.     public byte[] getBinaryData(ResultSet rs, int index) throws SQLException{
  53.         // Get as a BLOB
  54.         Blob aBlob = rs.getBlob(index);
  55.         if (aBlob == null) {
  56.             return null;
  57.         }
  58.         return aBlob.getBytes(1, (int) aBlob.length());
  59.     }

  60.     /**
  61.      * Si occupa di ottenere il messaggio precedentemente salvato sul DB,
  62.      * effettuando una get all'indice <var>index</var>.
  63.      *
  64.      * @param rs ResultSet da utilizzare.
  65.      * @param rsName Nome rs su cui prelevare il messaggio
  66.      *
  67.      */
  68.     @Override
  69.     public byte[] getBinaryData(ResultSet rs, String rsName) throws UtilsException,SQLException{
  70.         // Get as a BLOB
  71.         Blob aBlob = rs.getBlob(rsName);
  72.         if (aBlob == null) {
  73.             return null;
  74.         }
  75.         return aBlob.getBytes(1, (int) aBlob.length());
  76.     }


  77.    
  78.    
  79.    
  80.     /* ***** INPUT STREAM ****** */
  81.    
  82.     /**
  83.      * Si occupa di ottenere il messaggio precedentemente salvato sul DB,
  84.      * effettuando una get all'indice <var>index</var>.
  85.      *
  86.      * @param rs ResultSet da utilizzare.
  87.      * @param index Indice su cui prelevare il messaggio
  88.      *
  89.      */
  90.     @Override
  91.     public InputStream getBinaryStream(ResultSet rs, int index) throws UtilsException,SQLException{
  92.         // Get as a BLOB
  93.         Blob aBlob = rs.getBlob(index);
  94.         if (aBlob == null) {
  95.             return null;
  96.         }
  97.         return aBlob.getBinaryStream();
  98.     }
  99.    
  100.     /**
  101.      * Si occupa di ottenere il messaggio precedentemente salvato sul DB,
  102.      * effettuando una get all'indice <var>index</var>.
  103.      *
  104.      * @param rs ResultSet da utilizzare.
  105.      * @param rsName Nome rs su cui prelevare il messaggio
  106.      *
  107.      */
  108.     @Override
  109.     public InputStream getBinaryStream(ResultSet rs, String rsName) throws UtilsException,SQLException{
  110.         // Get as a BLOB
  111.         Blob aBlob = rs.getBlob(rsName);
  112.         if (aBlob == null) {
  113.             return null;
  114.         }
  115.         return aBlob.getBinaryStream();
  116.     }

  117. }