package com.tarisan.control; import com.tarisan.data.TTFranquiciasDentales; import com.tarisan.data.Tamedico; import com.tarisan.excepcion.*; import com.tarisan.log.*; import com.tarisan.util.Utilidades; import java.sql.*; import java.util.Vector; public class PersistenciaTTFranquiciasDentales { /** * 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; } /** * Obtiene una franquicia dental. * @param especialidad Numero de especialidad. * @param entidad Número de entidad. * @param colectivo Número de colectivo. * @param anio. * @return Objeto TTFranquiciasDentales. * @throws */ public Vector obtenerFranquicia(int especialidad, int entidad, long colectivo, int anio, String busquedaActo, int pagina) throws ExcepcionTarisan { int elementosPaginacion=1; Vector vResultado = new Vector(); TTFranquiciasDentales ttFranquiciasDentales = null; StringBuffer strSql = new StringBuffer(); Object aCondiciones[]=null; try { strSql.append("SELECT ttfranquicias_dentales.precio, ttfranquicias_dentales.acto, ttactmed.descripcion"); strSql.append(" FROM ttfranquicias_dentales, ttactmed"); strSql.append(" WHERE ttactmed.especialidad = TTFRANQUICIAS_DENTALES.ESPECIALIDAD"); strSql.append(" AND ttactmed.ACTO = TTFRANQUICIAS_DENTALES.ACTO"); strSql.append(" AND ttfranquicias_dentales.especialidad=?"); strSql.append(" AND ttfranquicias_dentales.entidad=?"); strSql.append(" AND ttfranquicias_dentales.colectivo=?"); strSql.append(" AND ttfranquicias_dentales.anio=?"); //comprobamos si se trata de una busqueda de actos medicos if (!busquedaActo.equalsIgnoreCase("")) //la sql tiene tres parametros { if (busquedaActo.endsWith("*")) busquedaActo=busquedaActo.replace('*', '%'); else busquedaActo="%" + busquedaActo + "%"; strSql.append(" AND ttactmed.descripcion LIKE ?"); //el array de objetos sera de tres elementos aCondiciones = new Object[5]; aCondiciones[4] = busquedaActo; } else //la sql solo tiene dos parametros aCondiciones = new Object[4]; aCondiciones[0] = Integer.valueOf(especialidad); aCondiciones[1] = Integer.valueOf(entidad); aCondiciones[2] = Long.valueOf(colectivo); aCondiciones[3] = Integer.valueOf(anio); Connection conexion = ParametrosConfiguracion.dataStore.obtenerConexion(); LogTarisan.logger.log(NivelLog.DEBUG, Utilidades.obtenerSentenciaSQL(strSql, null, aCondiciones)); ResultSet rs = ParametrosConfiguracion.dataStore.seleccionar(conexion, strSql.toString(), aCondiciones); objPaginacion.inicializarPaginacion(rs); if (objPaginacion.getNumeroRegistrosTotales()!=0) { objPaginacion.realizarPaginacion(rs, pagina); while(rs.next() && (elementosPaginacion <= Paginacion.getFilasPorPagina())) { ttFranquiciasDentales = new TTFranquiciasDentales(); ttFranquiciasDentales.setEspecialidad(especialidad); ttFranquiciasDentales.setActo(rs.getInt("ACTO")); ttFranquiciasDentales.setEntidad(entidad); ttFranquiciasDentales.setColectivo(colectivo); ttFranquiciasDentales.setAnio(anio); ttFranquiciasDentales.setPrecio(rs.getInt("PRECIO")); ttFranquiciasDentales.setDescripcion(rs.getString("DESCRIPCION")); vResultado.addElement(ttFranquiciasDentales); if (pagina!=0) //Se quiere realizar la paginacion elementosPaginacion++; } } rs.close(); ParametrosConfiguracion.dataStore.liberarConexion(conexion); LogTarisan.logger.log(NivelLog.DEBUG, "Franquicia dental obtenida de la tabla ttfranquicias_dentales es: (" + strSql.toString() + ")"); } catch (ExcepcionTarisan sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de ttfranquicias_dentales: " + sqle + " (" + strSql.toString() + ")"); throw (ExcepcionTarisan)sqle; } catch(SQLException sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de ttfranquicias_dentales: " + sqle + " (" + strSql.toString() + ")"); throw new ExcepcionTarisan(sqle.getMessage()); } catch(Exception sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de ttfranquicias_dentales: " + sqle + " (" + strSql.toString() + ")"); throw new ExcepcionTarisan(sqle.getMessage()); } catch(Throwable sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de ttfranquicias_dentales: " + sqle + " (" + strSql.toString() + ")"); throw new ExcepcionTarisan(sqle.getMessage()); } return vResultado; } public int obtenerNumeroFranquicia(int especialidad, int entidad, long colectivo, int anio) { int resultado = 0; StringBuffer strSql = new StringBuffer(); Object aCondiciones[]=null; try { strSql.append("SELECT distinct(ttfranquicias_dentales.tipo_franquicia)"); strSql.append(" FROM ttfranquicias_dentales"); strSql.append(" WHERE ttfranquicias_dentales.especialidad=?"); strSql.append(" AND ttfranquicias_dentales.entidad=?"); strSql.append(" AND ttfranquicias_dentales.colectivo=?"); strSql.append(" AND ttfranquicias_dentales.anio=?"); aCondiciones = new Object[4]; aCondiciones[0] = Integer.valueOf(especialidad); aCondiciones[1] = Integer.valueOf(entidad); aCondiciones[2] = Long.valueOf(colectivo); aCondiciones[3] = Integer.valueOf(anio); Connection conexion = ParametrosConfiguracion.dataStore.obtenerConexion(); LogTarisan.logger.log(NivelLog.DEBUG, Utilidades.obtenerSentenciaSQL(strSql, null, aCondiciones)); ResultSet rs = ParametrosConfiguracion.dataStore.seleccionar(conexion, strSql.toString(), aCondiciones); if(rs.next()) { resultado = rs.getInt("TIPO_FRANQUICIA"); } rs.close(); ParametrosConfiguracion.dataStore.liberarConexion(conexion); LogTarisan.logger.log(NivelLog.DEBUG, "Franquicia dental obtenida de la tabla ttfranquicias_dentales es: (" + strSql.toString() + ")"); } catch (ExcepcionTarisan sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de ttfranquicias_dentales: " + sqle + " (" + strSql.toString() + ")"); } catch(SQLException sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de ttfranquicias_dentales: " + sqle + " (" + strSql.toString() + ")"); } catch(Exception sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de ttfranquicias_dentales: " + sqle + " (" + strSql.toString() + ")"); } catch(Throwable sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de ttfranquicias_dentales: " + sqle + " (" + strSql.toString() + ")"); } return resultado; } public int obtenerNumeroFranquiciaPorContrato(int contrato) { int resultado = 0; StringBuffer strSql = new StringBuffer(); Object aCondiciones[]=null; try { strSql.append("SELECT distinct(ttfranquicias_dentales.tipo_franquicia)"); strSql.append(" FROM ttfranquicias_dentales"); strSql.append(" WHERE ttfranquicias_dentales.contrato=?"); aCondiciones = new Object[1]; aCondiciones[0] = Integer.valueOf(contrato); Connection conexion = ParametrosConfiguracion.dataStore.obtenerConexion(); LogTarisan.logger.log(NivelLog.DEBUG, Utilidades.obtenerSentenciaSQL(strSql, null, aCondiciones)); ResultSet rs = ParametrosConfiguracion.dataStore.seleccionar(conexion, strSql.toString(), aCondiciones); if(rs.next()) { resultado = rs.getInt("TIPO_FRANQUICIA"); } rs.close(); ParametrosConfiguracion.dataStore.liberarConexion(conexion); LogTarisan.logger.log(NivelLog.DEBUG, "Franquicia dental obtenida de la tabla ttfranquicias_dentales es: (" + strSql.toString() + ")"); } catch (ExcepcionTarisan sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de ttfranquicias_dentales: " + sqle + " (" + strSql.toString() + ")"); } catch(SQLException sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de ttfranquicias_dentales: " + sqle + " (" + strSql.toString() + ")"); } catch(Exception sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de ttfranquicias_dentales: " + sqle + " (" + strSql.toString() + ")"); } catch(Throwable sqle) { LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de ttfranquicias_dentales: " + sqle + " (" + strSql.toString() + ")"); } return resultado; } }