/** * @(#) PersistenciaTacentro.java */ package com.tarisan.control; import com.tarisan.data.Tacentro; import com.tarisan.log.*; import com.tarisan.excepcion.ExcepcionTarisan; import java.sql.*; import java.util.Vector; /** * Controla los accesos a la persistencia para la entidad Tacentro. * @author Dpto. Informática. * @version 1.0, 24/09/2003 */ public class PersistenciaTacentro { /** * Obtiene los centros existentes de la tabla TACENTRO * @return El Vector con la totalidad de los centros. * @throws */ @SuppressWarnings({ "rawtypes", "unchecked" }) public Vector obtenerCentros() throws ExcepcionTarisan { Vector vResultado = new Vector(); Tacentro tacentro = null; StringBuffer strSql = new StringBuffer(); try { strSql.append("SELECT CODIGO, DESCRIPCION"); strSql.append(" FROM tacentro"); Connection conexion = ParametrosConfiguracion.dataStore.obtenerConexion(); ResultSet rs = ParametrosConfiguracion.dataStore.seleccionar(conexion, strSql.toString()); while(rs.next()) { tacentro = new Tacentro(); tacentro.setCodigo(rs.getString("CODIGO")); tacentro.setDescripcion(rs.getString("DESCRIPCION")); vResultado.addElement(tacentro); } rs.close(); ParametrosConfiguracion.dataStore.liberarConexion(conexion); LogTarisan.logger.log(NivelLog.DEBUG, "Seleccionados " + vResultado.size() + " registros de la tabla TACENTRO (" + strSql.toString() + ")"); } catch (ExcepcionTarisan sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TACENTRO: " + sqle + " (" + strSql.toString() + ")"); throw (ExcepcionTarisan)sqle; } catch(SQLException sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TACENTRO: " + sqle + " (" + strSql.toString() + ")"); throw new ExcepcionTarisan(sqle.getMessage()); } catch(Exception sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TACENTRO: " + sqle + " (" + strSql.toString() + ")"); throw new ExcepcionTarisan(sqle.getMessage()); } catch(Throwable sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TACENTRO: " + sqle + " (" + strSql.toString() + ")"); throw new ExcepcionTarisan(sqle.getMessage()); } return vResultado; } /** * Obtiene el centro asociado al código del centro indicado. * @param codigo Código del centro. * @return El objeto Tacentro asociado al codigo del centro indicado. * @throws */ public Tacentro obtenerCentro(String codigo) throws ExcepcionTarisan { Tacentro tacentro = null; StringBuffer strSql = new StringBuffer(); Object[] aCondiciones=null; try { strSql.append("SELECT CODIGO, DESCRIPCION"); strSql.append(" FROM TACENTRO"); strSql.append(" WHERE CODIGO=?"); aCondiciones = new Object[1]; aCondiciones[0] = codigo; Connection conexion = ParametrosConfiguracion.dataStore.obtenerConexion(); ResultSet rs = ParametrosConfiguracion.dataStore.seleccionar(conexion, strSql.toString(), aCondiciones); if(rs.next()) { tacentro = new Tacentro(); tacentro.setCodigo(rs.getString("CODIGO")); tacentro.setDescripcion(rs.getString("DESCRIPCION")); } LogTarisan.logger.log(NivelLog.DEBUG, "Seleccionado " + rs.getRow() + " registros de la tabla TACENTRO (" + strSql.toString() + ")"); rs.close(); ParametrosConfiguracion.dataStore.liberarConexion(conexion); } catch (ExcepcionTarisan sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TACENTRO: " + sqle + " (" + strSql.toString() + ")"); throw (ExcepcionTarisan)sqle; } catch(SQLException sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TACENTRO: " + sqle + " (" + strSql.toString() + ")"); throw new ExcepcionTarisan(sqle.getMessage()); } catch(Exception sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TACENTRO: " + sqle + " (" + strSql.toString() + ")"); throw new ExcepcionTarisan(sqle.getMessage()); } catch(Throwable sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TACENTRO: " + sqle + " (" + strSql.toString() + ")"); throw new ExcepcionTarisan(sqle.getMessage()); } return tacentro; } }