280 lines
10 KiB
Java
280 lines
10 KiB
Java
package com.tarisan.control;
|
|
|
|
import java.sql.Connection;
|
|
import java.sql.ResultSet;
|
|
import java.sql.SQLException;
|
|
import java.util.Vector;
|
|
|
|
import com.tarisan.data.Tanoticias;
|
|
import com.tarisan.data.Tavolin;
|
|
import com.tarisan.excepcion.ExcepcionTarisan;
|
|
import com.tarisan.log.LogTarisan;
|
|
import com.tarisan.log.NivelLog;
|
|
import com.tarisan.util.Utilidades;
|
|
|
|
public class PersistenciaTanoticias {
|
|
|
|
/**
|
|
* El objeto <code>Paginacion</code> que controla el número de filas a mostrar por cada página.
|
|
*/
|
|
private Paginacion objPaginacion = new Paginacion();
|
|
|
|
/**
|
|
* Obtiene el valor del objeto <code>Paginacion</code> para saber que página se está visualizando.
|
|
* @return El objeto <code>Paginacion</code>.
|
|
*/
|
|
public Paginacion getPaginacion()
|
|
{
|
|
return objPaginacion;
|
|
}
|
|
|
|
public Vector seleccionar(String sqlSelect, Object[] aCondiciones) throws ExcepcionTarisan
|
|
{
|
|
Vector vResultado = new Vector();
|
|
Tanoticias tanoticias = null;
|
|
try
|
|
{
|
|
Connection conexion = ParametrosConfiguracion.dataStore.obtenerConexion();
|
|
ResultSet rs = ParametrosConfiguracion.dataStore.seleccionar(conexion, sqlSelect, aCondiciones);
|
|
|
|
while(rs.next())
|
|
{
|
|
tanoticias = new Tanoticias();
|
|
tanoticias.setId_noticia(rs.getInt("ID_NOTICIA"));
|
|
tanoticias.setNoticia(rs.getString("NOTICIA"));
|
|
tanoticias.setFecha(rs.getDate("FECHA"));
|
|
tanoticias.setCabecera(rs.getInt("CABECERA"));
|
|
vResultado.addElement(tanoticias);
|
|
}
|
|
rs.close();
|
|
ParametrosConfiguracion.dataStore.liberarConexion(conexion);
|
|
LogTarisan.logger.log(NivelLog.DEBUG, "Seleccionados " + vResultado.size() + " registros de la tabla TANOTICIAS (" + sqlSelect + ")");
|
|
}
|
|
catch (ExcepcionTarisan sqle)
|
|
{
|
|
LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TANOTICIAS: " + sqle + " (" + sqlSelect + ")");
|
|
throw (ExcepcionTarisan)sqle;
|
|
}
|
|
catch(SQLException sqle)
|
|
{
|
|
LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TANOTICIAS: " + sqle + " (" + sqlSelect + ")");
|
|
throw new ExcepcionTarisan(sqle.getMessage());
|
|
}
|
|
catch(Exception sqle)
|
|
{
|
|
LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TANOTICIAS: " + sqle + " (" + sqlSelect + ")");
|
|
throw new ExcepcionTarisan(sqle.getMessage());
|
|
}
|
|
catch(Throwable sqle)
|
|
{
|
|
LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TANOTICIAS: " + sqle + " (" + sqlSelect + ")");
|
|
throw new ExcepcionTarisan(sqle.getMessage());
|
|
|
|
}
|
|
|
|
return vResultado;
|
|
}
|
|
|
|
public int obtener_ultima_noticia(int medico)
|
|
{
|
|
StringBuffer strSql = new StringBuffer();
|
|
int resultado = 0;
|
|
|
|
strSql.append("select max(id_noticia) as ultima from tanoticias");
|
|
|
|
try
|
|
{
|
|
Connection conexion = ParametrosConfiguracion.dataStore.obtenerConexion();
|
|
ResultSet rs = ParametrosConfiguracion.dataStore.seleccionar(conexion, strSql.toString());
|
|
|
|
if (rs.next())
|
|
resultado = rs.getInt("ULTIMA");
|
|
|
|
rs.close();
|
|
ParametrosConfiguracion.dataStore.liberarConexion(conexion);
|
|
LogTarisan.logger.log(NivelLog.DEBUG, medico + " - Seleccionado el valor " + resultado + " del campo id_noticia de la tabla TANOTICIAS (" + strSql.toString() + ")");
|
|
}
|
|
catch (ExcepcionTarisan sqle)
|
|
{
|
|
LogTarisan.logger.log(NivelLog.ERROR, medico + " - Error en la selección de TANOTICIAS: " + sqle + " (" + strSql.toString() + ")");
|
|
|
|
}
|
|
catch(SQLException sqle)
|
|
{
|
|
LogTarisan.logger.log(NivelLog.ERROR, medico + " - Error en la selección de TANOTICIAS: " + sqle + " (" + strSql.toString() + ")");
|
|
|
|
}
|
|
catch(Exception sqle)
|
|
{
|
|
LogTarisan.logger.log(NivelLog.ERROR, medico + " - Error en la selección de TANOTICIAS: " + sqle + " (" + strSql.toString() + ")");
|
|
|
|
}
|
|
|
|
|
|
return resultado;
|
|
}
|
|
|
|
public Vector obtener_noticia(int id_noticia)
|
|
{
|
|
Vector resul = new Vector();
|
|
StringBuffer strSql = new StringBuffer();
|
|
|
|
Object [] aCondiciones = new Object[1];
|
|
String consulta = "";
|
|
|
|
strSql.append("select id_noticia, noticia, fecha, cabecera");
|
|
strSql.append(" from tanoticias");
|
|
strSql.append(" where id_noticia = ?");
|
|
|
|
aCondiciones[0] = Integer.valueOf(id_noticia);
|
|
|
|
try {
|
|
resul = this.seleccionar(strSql.toString(), aCondiciones);
|
|
consulta = Utilidades.obtenerSentenciaSQL(strSql, null, aCondiciones);
|
|
} catch (ExcepcionTarisan e) {
|
|
LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de Tanoticias (obtener_noticia): " + e + " (" + consulta + ")");
|
|
}
|
|
|
|
return resul;
|
|
}
|
|
|
|
public Vector obtener_noticias(int medico, int espe, int pagina)
|
|
{
|
|
int elementosPaginacion=1;
|
|
Vector vResultado = new Vector();
|
|
Tanoticias tanoticias = null;
|
|
String consulta = "";
|
|
consulta="SELECT TN.ID_NOTICIA, TN.NOTICIA, TN.FECHA, TN.CABECERA FROM TANOTICIAS TN, TANOTICIA_ESPECIALIDAD TNE WHERE TN.ID_NOTICIA = TNE.NOTICIA AND TNE.ESPECIALIDAD = 0 UNION SELECT TN.ID_NOTICIA, TN.NOTICIA, TN.FECHA, TN.CABECERA FROM TANOTICIAS TN, TANOTICIA_ESPECIALIDAD TNE WHERE TN.ID_NOTICIA = TNE.NOTICIA AND TNE.MEDICO = "+ medico + " UNION SELECT TN.ID_NOTICIA, TN.NOTICIA, TN.FECHA, TN.CABECERA FROM TANOTICIAS TN, TANOTICIA_ESPECIALIDAD TNE WHERE TN.ID_NOTICIA = TNE.NOTICIA AND TNE.ESPECIALIDAD = "+ espe +" AND TNE.MEDICO IS NULL ORDER BY FECHA DESC";
|
|
|
|
try
|
|
{
|
|
Connection conexion = ParametrosConfiguracion.dataStore.obtenerConexion();
|
|
ResultSet rs = ParametrosConfiguracion.dataStore.seleccionar(conexion, consulta);
|
|
|
|
objPaginacion.inicializarPaginacion(rs);
|
|
if (objPaginacion.getNumeroRegistrosTotales()!=0)
|
|
{
|
|
objPaginacion.realizarPaginacion(rs, pagina);
|
|
|
|
while(rs.next() && (elementosPaginacion <= Paginacion.getFilasPorPagina()))
|
|
{
|
|
tanoticias = new Tanoticias();
|
|
tanoticias.setId_noticia(rs.getInt("ID_NOTICIA"));
|
|
tanoticias.setNoticia(rs.getString("NOTICIA"));
|
|
tanoticias.setFecha(rs.getDate("FECHA"));
|
|
tanoticias.setCabecera(rs.getInt("CABECERA"));
|
|
vResultado.addElement(tanoticias);
|
|
if (pagina!=0) //Se quiere realizar la paginacion
|
|
elementosPaginacion++;
|
|
}
|
|
}
|
|
rs.close();
|
|
ParametrosConfiguracion.dataStore.liberarConexion(conexion);
|
|
LogTarisan.logger.log(NivelLog.DEBUG, "Seleccionados " + vResultado.size() + " registros de la tabla TANOTICIAS (" + consulta + ")");
|
|
}
|
|
catch (ExcepcionTarisan sqle)
|
|
{
|
|
LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TANOTICIAS: " + sqle + " (" + consulta + ")");
|
|
}
|
|
catch(SQLException sqle)
|
|
{
|
|
LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TANOTICIAS: " + sqle + " (" + consulta + ")");
|
|
}
|
|
catch(Exception sqle)
|
|
{
|
|
LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TANOTICIAS: " + sqle + " (" + consulta + ")");
|
|
}
|
|
|
|
return vResultado;
|
|
}
|
|
|
|
|
|
public boolean insertarNoticiaLeida(int noticia, int medico)
|
|
{
|
|
boolean resultado=false;
|
|
String consulta = "";
|
|
|
|
try {
|
|
Connection conexion = ParametrosConfiguracion.dataStore.obtenerConexion();
|
|
LogTarisan.logger.log(NivelLog.DEBUG, "\n Vamos ainsertar la noticia: "+noticia+", del medico: "+medico+" en la tabla TANOTICIAS_LEIDAS");
|
|
consulta = "INSERT INTO TANOTICIAS_LEIDAS (NOTICIA,MEDICO,FECHA) VALUES (" + noticia + "," + medico + ",SYSDATE)";
|
|
|
|
resultado = ParametrosConfiguracion.dataStore.insertar(consulta, conexion);
|
|
|
|
} catch (ExcepcionTarisan e) {
|
|
LogTarisan.logger.log(NivelLog.ERROR, "Error al insertar la noticia");
|
|
}
|
|
|
|
|
|
return resultado;
|
|
}
|
|
|
|
public Vector obtener_noticias_cabecera()
|
|
{
|
|
Vector resul = new Vector();
|
|
|
|
Object [] aCondiciones = new Object[0];
|
|
String consulta = "";
|
|
|
|
consulta = "select id_noticia, noticia, fecha, cabecera from tanoticias where cabecera = 1";
|
|
|
|
try {
|
|
resul = this.seleccionar(consulta, aCondiciones);
|
|
} catch (ExcepcionTarisan e) {
|
|
LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de Tanoticias (obtener_noticias_cabecera): " + e + " (" + consulta + ")");
|
|
}
|
|
|
|
return resul;
|
|
}
|
|
|
|
public Vector obtener_noticias_no_leidas(int medico, int espe, int pagina)
|
|
{
|
|
int elementosPaginacion=1;
|
|
Vector vResultado = new Vector();
|
|
Tanoticias tanoticias = null;
|
|
String consulta = "";
|
|
consulta="SELECT TN.ID_NOTICIA, TN.NOTICIA, TN.FECHA, TN.CABECERA FROM TANOTICIAS TN, TANOTICIA_ESPECIALIDAD TNE WHERE TN.ID_NOTICIA = TNE.NOTICIA AND TNE.ESPECIALIDAD = 0 UNION SELECT TN.ID_NOTICIA, TN.NOTICIA, TN.FECHA, TN.CABECERA FROM TANOTICIAS TN, TANOTICIA_ESPECIALIDAD TNE WHERE TN.ID_NOTICIA = TNE.NOTICIA AND TNE.MEDICO = "+ medico + " UNION SELECT TN.ID_NOTICIA, TN.NOTICIA, TN.FECHA, TN.CABECERA FROM TANOTICIAS TN, TANOTICIA_ESPECIALIDAD TNE WHERE TN.ID_NOTICIA = TNE.NOTICIA AND TNE.ESPECIALIDAD = "+ espe +" AND TNE.MEDICO IS NULL MINUS SELECT TN.ID_NOTICIA, TN.NOTICIA, TN.FECHA, TN.CABECERA FROM TANOTICIAS TN, TANOTICIAS_LEIDAS TNL WHERE TN.ID_NOTICIA = TNL.NOTICIA AND TNL.MEDICO = "+ medico + " ORDER BY FECHA DESC";
|
|
|
|
try
|
|
{
|
|
Connection conexion = ParametrosConfiguracion.dataStore.obtenerConexion();
|
|
ResultSet rs = ParametrosConfiguracion.dataStore.seleccionar(conexion, consulta);
|
|
|
|
objPaginacion.inicializarPaginacion(rs);
|
|
if (objPaginacion.getNumeroRegistrosTotales()!=0)
|
|
{
|
|
objPaginacion.realizarPaginacion(rs, pagina);
|
|
|
|
while(rs.next() && (elementosPaginacion <= Paginacion.getFilasPorPagina()))
|
|
{
|
|
tanoticias = new Tanoticias();
|
|
tanoticias.setId_noticia(rs.getInt("ID_NOTICIA"));
|
|
tanoticias.setNoticia(rs.getString("NOTICIA"));
|
|
tanoticias.setFecha(rs.getDate("FECHA"));
|
|
tanoticias.setCabecera(rs.getInt("CABECERA"));
|
|
vResultado.addElement(tanoticias);
|
|
if (pagina!=0) //Se quiere realizar la paginacion
|
|
elementosPaginacion++;
|
|
}
|
|
}
|
|
rs.close();
|
|
ParametrosConfiguracion.dataStore.liberarConexion(conexion);
|
|
LogTarisan.logger.log(NivelLog.DEBUG, "Seleccionados " + vResultado.size() + " registros de la tabla TANOTICIAS (" + consulta + ")");
|
|
}
|
|
catch (ExcepcionTarisan sqle)
|
|
{
|
|
LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TANOTICIAS: " + sqle + " (" + consulta + ")");
|
|
}
|
|
catch(SQLException sqle)
|
|
{
|
|
LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TANOTICIAS: " + sqle + " (" + consulta + ")");
|
|
}
|
|
catch(Exception sqle)
|
|
{
|
|
LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TANOTICIAS: " + sqle + " (" + consulta + ")");
|
|
}
|
|
|
|
return vResultado;
|
|
}
|
|
}
|