Se agrego logeo a la clase SQLiteEfectivoDAO
Se corrigio igual un error en el logeo de SQLiteDocumentosDAO Y finalmente se configuro log4j2 para que logee todo
This commit is contained in:
@@ -134,6 +134,7 @@ public class SQLiteDocumentosDAO implements DocumentosDAO {
|
||||
Documentos documentos = null;
|
||||
|
||||
if (Caja.EMPTY == caja) {
|
||||
LOGGER.trace("La caja entregada era Caja.EMPTY");
|
||||
return Optional.ofNullable(documentos);
|
||||
}
|
||||
|
||||
@@ -251,7 +252,7 @@ public class SQLiteDocumentosDAO implements DocumentosDAO {
|
||||
|
||||
/**
|
||||
* Actualiza un Documentos existente en la base de datos
|
||||
* @param documentos el documentos a insertar
|
||||
* @param documentos el documentos a actualizar
|
||||
*/
|
||||
@Override
|
||||
public void updateDocumentos(Documentos documentos) {
|
||||
|
||||
@@ -36,16 +36,28 @@ import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
/**
|
||||
* Objeto DAO que realiza las querys y mapeos necesarios del objeto Efectivo
|
||||
* En especifico esta implementacion se comunica con la base de datos SQLite
|
||||
*/
|
||||
public class SQLiteEfectivoDAO implements EfectivoDAO {
|
||||
private static final Logger LOGGER = LogManager.getLogger(SQLiteEfectivoDAO.class);
|
||||
private ConnectionHolder connectionHolder;
|
||||
|
||||
public SQLiteEfectivoDAO() {
|
||||
this.connectionHolder = new SQLiteConnectionHolder();
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtiene todas las instancias de Efectivo que existen en la base de datos
|
||||
* @return una lista de Efectivo
|
||||
*/
|
||||
@Override
|
||||
public List<Efectivo> getAll() {
|
||||
LOGGER.info("Se intentara conseguir todas los Efectivo");
|
||||
List<Efectivo> efectivoList = new ArrayList<>();
|
||||
String query = "select * from efectivos";
|
||||
try (Connection conn = connectionHolder.getConnection()) {
|
||||
@@ -75,13 +87,22 @@ public class SQLiteEfectivoDAO implements EfectivoDAO {
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
LOGGER.error("Erro al intentar conseguir todos los Efectivo", e);
|
||||
}
|
||||
|
||||
LOGGER.trace("Se consiguieron " + efectivoList.size() + " Efectivo");
|
||||
return efectivoList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtiene un Efectivo dado su id en la base de datos
|
||||
* @param id el id de la fila del efectivo en la base de datos
|
||||
* @return un optional que contiene el efectivo y puede estar vacio, dado que no es
|
||||
* 100% seguro que el id entregado sea valido o exista en la base de datos.
|
||||
*/
|
||||
@Override
|
||||
public Optional<Efectivo> getById(int id) {
|
||||
LOGGER.info("Se intentara conseguir un Efectivo con id " + id);
|
||||
Efectivo efectivo = null;
|
||||
String query = "select * from efectivos where id = ?";
|
||||
try (Connection conn = connectionHolder.getConnection()) {
|
||||
@@ -110,15 +131,25 @@ public class SQLiteEfectivoDAO implements EfectivoDAO {
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
LOGGER.error("Error al intentar conseguir un Efectivo con id " + id);
|
||||
}
|
||||
|
||||
LOGGER.trace("Se consiguio el efectivo " + efectivo);
|
||||
return Optional.ofNullable(efectivo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtiene un Efectivo perteneciente a una caja
|
||||
* @param caja Caja a la cual pertenece el efectivo requerido
|
||||
* @return Un optional que contiene el efectivo y puede estar vacio, dado que no es 100%
|
||||
* seguro que la exista un efectivo para la caja. Ademas la caja puede ser Caja.EMPTY
|
||||
* en ese caso siempre se retornara un Optional.empty().
|
||||
*/
|
||||
@Override
|
||||
public Optional<Efectivo> getByCaja(Caja caja) {
|
||||
LOGGER.info("Se intentara conseguir un Efectivo perteneciente a la caja " + caja);
|
||||
Efectivo efectivo = null;
|
||||
if (Caja.EMPTY == caja) {
|
||||
LOGGER.trace("La caja entregada era Caja.EMPTY");
|
||||
return Optional.ofNullable(efectivo);
|
||||
}
|
||||
|
||||
@@ -144,15 +175,26 @@ public class SQLiteEfectivoDAO implements EfectivoDAO {
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
LOGGER.error("Error al intentar conseguir un Efectivo perteneciente a la caja " + caja );
|
||||
}
|
||||
|
||||
LOGGER.trace("Se obtuvo el efectivo " + efectivo);
|
||||
return Optional.ofNullable(efectivo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtiene la suma de los efectivos pertenecientes una caja
|
||||
* @param caja Caja a la cual pertenece los efectivos a sumar
|
||||
* @return Un int con la suma obtenida, en caso que la caja sea igual a Caja.EMPTY
|
||||
* simplemente se retoranara 0, al igual que cuando no exista ningun efectivo para esa caja
|
||||
*/
|
||||
@Override
|
||||
public int getTotalEfectivo(Caja caja) {
|
||||
LOGGER.info("Se intentara conseguir la suma de efectivos de la caja " + caja);
|
||||
int total = 0;
|
||||
|
||||
if (Caja.EMPTY == caja) {
|
||||
LOGGER.trace("La caja entregada era Caja.EMPTY");
|
||||
return total;
|
||||
}
|
||||
|
||||
@@ -167,12 +209,20 @@ public class SQLiteEfectivoDAO implements EfectivoDAO {
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
LOGGER.error("Error al intentar conseguir la suma de efectivos con la caja " + caja);
|
||||
}
|
||||
|
||||
LOGGER.trace("La suma obtenida es " + total);
|
||||
return total;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserta en la base de datos una instancia de Efectivo nueva
|
||||
* @param efectivo Efectivo a insertar, una vez que ocurra se le otorgara un id.
|
||||
*/
|
||||
@Override
|
||||
public void insertEfectivo(Efectivo efectivo) {
|
||||
LOGGER.info("Se intentara insertar el efectivo " + efectivo);
|
||||
String query = "insert into efectivos (veinte_mil, diez_mil, cinco_mil, dos_mil, mil, quinientos, cien, cincuenta, diez, caja_id) values (?,?,?,?,?,?,?,?,?,?)";
|
||||
try (Connection conn = connectionHolder.getConnection()) {
|
||||
try (PreparedStatement ps = conn.prepareStatement(query)) {
|
||||
@@ -195,11 +245,19 @@ public class SQLiteEfectivoDAO implements EfectivoDAO {
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
LOGGER.error("Error al intentar insertar el efectivo " + efectivo, e);
|
||||
}
|
||||
LOGGER.trace("Se inserto el efectivo " + efectivo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserta un efectivo por default, teniendo todos los campos en 0 exceptuando el id de la caja
|
||||
* @param efectivo Instancia de efectivo que se guardara, solo se tomara en cuenta la caja
|
||||
* que almacena para obtener su id.
|
||||
*/
|
||||
@Override
|
||||
public void insertDefaultEfectivo(Efectivo efectivo) {
|
||||
LOGGER.info("Se intentara insertar el efectivo por default " + efectivo);
|
||||
String query = "insert into efectivos (veinte_mil, diez_mil, cinco_mil, dos_mil, mil, quinientos, cien, cincuenta, diez, caja_id) values (0,0,0,0,0,0,0,0,0,?)";
|
||||
try (Connection conn = connectionHolder.getConnection()) {
|
||||
try (PreparedStatement ps = conn.prepareStatement(query)) {
|
||||
@@ -213,11 +271,18 @@ public class SQLiteEfectivoDAO implements EfectivoDAO {
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
LOGGER.error("Error al insertar el efectivo por default " + efectivo, e);
|
||||
}
|
||||
LOGGER.trace("Se inserto el efectivo por default " + efectivo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Actualiza un Efectivo existente en la base de datos
|
||||
* @param efectivo efectivo a actualizar
|
||||
*/
|
||||
@Override
|
||||
public void updateEfectivo(Efectivo efectivo) {
|
||||
LOGGER.info("Se intentara actualizar el efectivo " + efectivo);
|
||||
String query = "update efectivos set veinte_mil = ?, diez_mil = ?, cinco_mil = ?, dos_mil = ?, mil = ?, quinientos = ?, cien = ?, cincuenta = ?, diez = ?, caja_id = ? where id = ?";
|
||||
try (Connection conn = connectionHolder.getConnection()) {
|
||||
try (PreparedStatement ps = conn.prepareStatement(query)) {
|
||||
@@ -236,11 +301,18 @@ public class SQLiteEfectivoDAO implements EfectivoDAO {
|
||||
ps.executeUpdate();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
LOGGER.error("Error al intentar actualizar el efectivo " + efectivo, e);
|
||||
}
|
||||
LOGGER.trace("Se actualizo el efectivo " + efectivo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Elimina un efectivo de la base de datos
|
||||
* @param efectivo efectivo a eliminar
|
||||
*/
|
||||
@Override
|
||||
public void deleteEfectivo(Efectivo efectivo) {
|
||||
LOGGER.info("Se intentara eliminar el efectivo " + efectivo);
|
||||
String query = "delete from efectivos where id = ?";
|
||||
try (Connection conn = connectionHolder.getConnection()) {
|
||||
try (PreparedStatement ps = conn.prepareStatement(query)) {
|
||||
@@ -248,7 +320,9 @@ public class SQLiteEfectivoDAO implements EfectivoDAO {
|
||||
ps.executeUpdate();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
LOGGER.error("Error al intentar eliminar el efectivo " + efectivo, e);
|
||||
}
|
||||
LOGGER.trace("Se elimino el efectivo " + efectivo);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,7 +4,9 @@ name = PropertiesConfig
|
||||
filters = threshold
|
||||
|
||||
filter.threshold.type = ThresholdFilter
|
||||
filter.threshold.level = debug
|
||||
filter.threshold.level = trace
|
||||
filter.threshold.onMatch = ACCEPT
|
||||
filter.threshold.onMismatch= NEUTRAL
|
||||
|
||||
appenders = console, file
|
||||
|
||||
|
||||
Reference in New Issue
Block a user