/** * @(#) PersistenciaTamensaje.java */ package com.tarisan.control; import com.tarisan.data.Tamensaje; import com.tarisan.log.*; import com.tarisan.util.Utilidades; import com.tarisan.excepcion.ExcepcionTarisan; import java.sql.*; import java.util.Vector; /** * Controla los accesos a la persistencia para la entidad TAMENSAJE. * @author Dpto. Informática. * @version 1.0, 24/09/2003 */ public class PersistenciaTamensaje { /** * El objeto Paginacion que controla el número de filas a mostrar por cada página. */ private Paginacion objPaginacion = new Paginacion(); /** * Obtiene el valor del objeto Paginacion para saber que página se está visualizando. * @return El objeto Paginacion. */ public Paginacion getPaginacion() { return objPaginacion; } /** * Selecciona los registros de la tabla TAMENSAJE en función de la sentencia SELECT indicada. * @param sqlSelect La sentencia SELECT de selección. * @param pagina Número de página a mostrar. * @param aCondiciones Array que contiene los parámetros utilizados en la sentencia SELECT. * @return El Vector con los registros seleccionados (todos pertenencientes a la clase Taespeci). * @throws */ public Tamensaje obtenerMensaje(int codigo) throws ExcepcionTarisan { Tamensaje tamensaje = null; ResultSet rs = null; StringBuffer strSql = new StringBuffer(); Object [] aCondiciones = new Object[1]; strSql.append("SELECT *"); strSql.append(" FROM TAMENSAJE"); strSql.append(" WHERE CODIGO = ?"); aCondiciones = new Object[1]; aCondiciones[0] = Integer.valueOf(codigo); strSql.append(" ORDER BY CODIGO"); try { Connection conexion = ParametrosConfiguracion.dataStore.obtenerConexion(); rs = ParametrosConfiguracion.dataStore.seleccionar(conexion, strSql.toString(), aCondiciones); if(rs.next()) { tamensaje = new Tamensaje(); tamensaje.setMensaje(rs.getString("MENSAJE")); tamensaje.setCodigo(rs.getInt("CODIGO")); } rs.close(); ParametrosConfiguracion.dataStore.liberarConexion(conexion); LogTarisan.logger.log(NivelLog.DEBUG, "Seleccionado un registro de la tabla TAMENSAJE (" + strSql.toString() + ")"); } catch (ExcepcionTarisan sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TAMENSAJE: " + sqle + " (" + strSql.toString() + ")"); throw (ExcepcionTarisan)sqle; } catch(SQLException sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TAMENSAJE: " + sqle + " (" + strSql.toString() + ")"); throw new ExcepcionTarisan(sqle.getMessage()); } catch(Exception sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TAMENSAJE: " + sqle + " (" + strSql.toString() + ")"); throw new ExcepcionTarisan(sqle.getMessage()); } catch(Throwable sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TAMENSAJE: " + sqle + " (" + strSql.toString() + ")"); throw new ExcepcionTarisan(sqle.getMessage()); } return tamensaje; } public Vector obtenerMensajes(String codigos) throws ExcepcionTarisan { Vector vTamensajes = new Vector(); ResultSet rs = null; StringBuffer strSql = new StringBuffer(); Object [] aCondiciones = new Object[1]; strSql.append("SELECT *"); strSql.append(" FROM TAMENSAJE"); strSql.append(" WHERE CODIGO in (?)"); aCondiciones = new Object[1]; aCondiciones[0] = codigos; strSql.append(" ORDER BY CODIGO"); try { Connection conexion = ParametrosConfiguracion.dataStore.obtenerConexion(); rs = ParametrosConfiguracion.dataStore.seleccionar(conexion, strSql.toString(), aCondiciones); if(rs.next()) { Tamensaje tamensaje = new Tamensaje(); tamensaje.setMensaje(rs.getString("MENSAJE")); tamensaje.setCodigo(rs.getInt("CODIGO")); vTamensajes.add(tamensaje); } rs.close(); ParametrosConfiguracion.dataStore.liberarConexion(conexion); LogTarisan.logger.log(NivelLog.DEBUG, "Seleccionado un registro de la tabla TAMENSAJE (" + strSql.toString() + ")"); } catch (ExcepcionTarisan sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TAMENSAJE: " + sqle + " (" + strSql.toString() + ")"); throw (ExcepcionTarisan)sqle; } catch(SQLException sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TAMENSAJE: " + sqle + " (" + strSql.toString() + ")"); throw new ExcepcionTarisan(sqle.getMessage()); } catch(Exception sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TAMENSAJE: " + sqle + " (" + strSql.toString() + ")"); throw new ExcepcionTarisan(sqle.getMessage()); } catch(Throwable sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TAMENSAJE: " + sqle + " (" + strSql.toString() + ")"); throw new ExcepcionTarisan(sqle.getMessage()); } return vTamensajes; } }