237 lines
7.1 KiB
Java
237 lines
7.1 KiB
Java
/**
|
|
* @(#) PersistenciaTaespeci.java
|
|
*/
|
|
|
|
package com.tarisan.control;
|
|
|
|
import com.tarisan.data.Taespeci;
|
|
import com.tarisan.data.TtactmedGPC;
|
|
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 <code>Taespeci</code>.
|
|
* @author <a href="mailto:sistemas@imqnavarra.com">Dpto. Informática</a>.
|
|
* @version 1.0, 24/09/2003
|
|
*/
|
|
public class PersistenciaTaespeci
|
|
{
|
|
|
|
/**
|
|
* 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;
|
|
}
|
|
|
|
/**
|
|
* Selecciona los registros de la tabla TAESPECI 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 <code>Taespeci</code>).
|
|
* @throws
|
|
*/
|
|
public Vector seleccionar(String sqlSelect, int pagina, Object[] aCondiciones) throws ExcepcionTarisan
|
|
{
|
|
|
|
int elementosPaginacion=1;
|
|
|
|
Vector vResultado = new Vector();
|
|
Taespeci taespeci = null;
|
|
ResultSet rs = null;
|
|
|
|
try
|
|
{
|
|
Connection conexion = ParametrosConfiguracion.dataStore.obtenerConexion();
|
|
if (aCondiciones==null || aCondiciones.length==0)
|
|
rs = ParametrosConfiguracion.dataStore.seleccionar(conexion, sqlSelect);
|
|
else
|
|
rs = ParametrosConfiguracion.dataStore.seleccionar(conexion, sqlSelect, aCondiciones);
|
|
|
|
objPaginacion.inicializarPaginacion(rs);
|
|
if (objPaginacion.getNumeroRegistrosTotales()!=0)
|
|
{
|
|
objPaginacion.realizarPaginacion(rs, pagina);
|
|
|
|
while(rs.next() && (elementosPaginacion <= Paginacion.getFilasPorPagina()))
|
|
{
|
|
taespeci = new Taespeci();
|
|
taespeci.setDescripcion(rs.getString("DESCRIPCION"));
|
|
taespeci.setEspecialidad(rs.getInt("ESPECIALIDAD"));
|
|
vResultado.addElement(taespeci);
|
|
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 TAESPECI (" + sqlSelect + ")");
|
|
|
|
|
|
}
|
|
|
|
catch (ExcepcionTarisan sqle)
|
|
{
|
|
LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TAESPECI: " + sqle + " (" + sqlSelect + ")");
|
|
throw (ExcepcionTarisan)sqle;
|
|
}
|
|
catch(SQLException sqle)
|
|
{
|
|
LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TAESPECI: " + sqle + " (" + sqlSelect + ")");
|
|
throw new ExcepcionTarisan(sqle.getMessage());
|
|
}
|
|
catch(Exception sqle)
|
|
{
|
|
LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TAESPECI: " + sqle + " (" + sqlSelect + ")");
|
|
throw new ExcepcionTarisan(sqle.getMessage());
|
|
}
|
|
catch(Throwable sqle)
|
|
{
|
|
LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de TAESPECI: " + sqle + " (" + sqlSelect + ")");
|
|
throw new ExcepcionTarisan(sqle.getMessage());
|
|
|
|
}
|
|
|
|
return vResultado;
|
|
}
|
|
|
|
public Vector listado_especialidades(String nombre, int intPagina)
|
|
{
|
|
Vector resul = new Vector();
|
|
StringBuffer strSql = new StringBuffer();
|
|
|
|
Object [] aCondiciones = new Object[1];
|
|
String consulta = "";
|
|
|
|
strSql.append("SELECT ESPECIALIDAD, DESCRIPCION");
|
|
strSql.append(" FROM TAESPECI");
|
|
strSql.append(" WHERE ESPECIALIDAD <> ?");
|
|
|
|
|
|
//comprobamos si se trata de una busqueda de especialidades
|
|
if (!nombre.equalsIgnoreCase(""))
|
|
{
|
|
if (nombre.endsWith("*"))
|
|
nombre=nombre.replace('*', '%');
|
|
else
|
|
nombre="%" + nombre + "%";
|
|
|
|
strSql.append(" AND DESCRIPCION LIKE ?");
|
|
|
|
aCondiciones = new Object[2];
|
|
aCondiciones[1] = new String(nombre);
|
|
}
|
|
else
|
|
aCondiciones = new Object[1];
|
|
aCondiciones[0] = Integer.valueOf(0);
|
|
|
|
strSql.append(" ORDER BY DESCRIPCION");
|
|
|
|
|
|
try {
|
|
resul = this.seleccionar(strSql.toString(), intPagina, aCondiciones);
|
|
consulta = Utilidades.obtenerSentenciaSQL(strSql, null, aCondiciones);
|
|
} catch (ExcepcionTarisan e) {
|
|
LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de Tapresca-taclient (listado_diagnostico_gpc_por_cliente): " + e + " (" + consulta + ")");
|
|
}
|
|
|
|
|
|
|
|
return resul;
|
|
}
|
|
|
|
public String obtenerDescripcionEspecialidad(int especialidad) throws SQLException
|
|
{
|
|
String resul = "";
|
|
StringBuffer strSql = new StringBuffer();
|
|
ResultSet rs = null;
|
|
Object [] aCondiciones = new Object[1];
|
|
|
|
strSql.append("SELECT DESCRIPCION");
|
|
strSql.append(" FROM TAESPECI");
|
|
strSql.append(" WHERE ESPECIALIDAD = ?");
|
|
|
|
aCondiciones = new Object[1];
|
|
aCondiciones[0] = especialidad;
|
|
|
|
try {
|
|
Connection conexion = ParametrosConfiguracion.dataStore.obtenerConexion();
|
|
rs = ParametrosConfiguracion.dataStore.seleccionar(conexion, strSql.toString(), aCondiciones);
|
|
|
|
if(rs.next())
|
|
{
|
|
resul = rs.getString("DESCRIPCION");
|
|
|
|
}
|
|
rs.close();
|
|
ParametrosConfiguracion.dataStore.liberarConexion(conexion);
|
|
LogTarisan.logger.log(NivelLog.DEBUG, "Seleccionada la especialidad " + resul + " de la tabla TAESPECI (" + strSql.toString() + ")");
|
|
|
|
} catch (ExcepcionTarisan e) {
|
|
LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de Taespeci (obtenerDescripcionEspecialidad): " + e + " (" + strSql.toString() + ")");
|
|
}
|
|
|
|
return resul;
|
|
}
|
|
|
|
public int paginaDeLaEspecialidad(int Especialidad) throws SQLException
|
|
{
|
|
int pagina = 0;
|
|
Vector resul = new Vector();
|
|
StringBuffer strSql = new StringBuffer();
|
|
Taespeci taespeci = null;
|
|
int pos = 0;
|
|
|
|
Object [] aCondiciones = new Object[0];
|
|
String consulta = "";
|
|
|
|
strSql.append("SELECT ESPECIALIDAD, DESCRIPCION");
|
|
strSql.append(" FROM TAESPECI");
|
|
strSql.append(" ORDER BY DESCRIPCION");
|
|
|
|
try {
|
|
Connection conexion = ParametrosConfiguracion.dataStore.obtenerConexion();
|
|
ResultSet rs = ParametrosConfiguracion.dataStore.seleccionar(conexion, strSql.toString(), aCondiciones);
|
|
|
|
while(rs.next())
|
|
{
|
|
pos = pos + 1;
|
|
taespeci = new Taespeci();
|
|
taespeci.setDescripcion(rs.getString("DESCRIPCION"));
|
|
taespeci.setEspecialidad(rs.getInt("ESPECIALIDAD"));
|
|
|
|
if (taespeci.getEspecialidad()==Especialidad){
|
|
pagina = (pos/10) + 1;
|
|
if (pos % 10 == 0){
|
|
pagina = pagina - 1;
|
|
}
|
|
}
|
|
}
|
|
rs.close();
|
|
ParametrosConfiguracion.dataStore.liberarConexion(conexion);
|
|
LogTarisan.logger.log(NivelLog.DEBUG, "Seleccionados " + resul.size() + " registros de la tabla tapresca_tarisan (" + strSql.toString() + ")");
|
|
consulta = Utilidades.obtenerSentenciaSQL(strSql, null, aCondiciones);
|
|
} catch (ExcepcionTarisan e) {
|
|
LogTarisan.logger.log(NivelLog.ERROR, "Error en la selección de Tapresca-taclient (listado_diagnostico_gpc_por_cliente): " + e + " (" + consulta + ")");
|
|
}
|
|
|
|
|
|
|
|
return pagina;
|
|
}
|
|
|
|
}
|