Files
sistema-caja/src/danielcortes/xyz/models/ingreso/IngresoDAO.java
Daniel Cortes 412e128398 Limpiado modelo de caja
Como consecuencia esto llevo a modificar otras clases que la utilizaban
ya que se decidieron cambiar un par de cosas en su API

- Quitar el que los metodos de update e insert retornaran un booleano,
realmente no era algo necesario y no se estaba utilizando.

- Remplazar el retornar una Caja por retornar un Optional<Caja> en los
metodos de getByFecha y getById, con el fin eliminar un poco los
chequeos de nulls

- El metodo de cajasFromResultSet fue eliminado ya que no lo veia
necesario ya que operaba generaba una List con las cajas obtenidas por
el ResultSet y los de los 2 metodos que la invocaban, solo uno de ellos
necesitaba una lista, el otro solo obtenia el primero de la lista y
continuaba.

- Cambie el necesitar un LocalDate en el metodo que genera las cajas
para un mes, por un objeto con logico para esta situacion, el cual es
YearMonth, esto tuvo como consecuencia la mayoria de los cambios fuera
de esta clase.

- Renombre los metodos para que tuvieran nombres mas agradables para mi,
esto es lo otro que hizo cambiar muchas otras clases.
2019-03-01 22:40:09 -03:00

99 lines
3.6 KiB
Java

/*
* MIT License
*
* Copyright (c) 2018-2019 Daniel Cortes
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package danielcortes.xyz.models.ingreso;
import danielcortes.xyz.data.ConnectionHolder;
import danielcortes.xyz.models.caja.Caja;
import danielcortes.xyz.models.caja.CajaDAO;
import danielcortes.xyz.models.caja.SQLiteCajaDAO;
import danielcortes.xyz.models.tipo_ingreso.SQLiteTipoIngresoDAO;
import danielcortes.xyz.models.tipo_ingreso.TipoIngreso;
import danielcortes.xyz.models.tipo_ingreso.TipoIngresoDAO;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.YearMonth;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
public abstract class IngresoDAO {
private static final Logger LOGGER = Logger.getLogger(IngresoDAO.class.getName());
protected ConnectionHolder connectionHolder;
public abstract List<Ingreso> findAll();
public abstract List<Ingreso> findByCaja(Caja caja);
public abstract List<Ingreso> findById(int id);
public abstract List<Ingreso> findByTipoIngreso(TipoIngreso tipoIngreso);
public abstract boolean insertIngreso(Ingreso ingreso);
public abstract boolean updateIngreso(Ingreso ingreso);
public abstract boolean deleteIngreso(Ingreso ingreso);
public abstract int getTotalIngreso(Caja caja);
public abstract int getTotalIngresoMes(YearMonth mes);
public abstract int getTotalExentasMes(YearMonth mes);
List<Ingreso> ingresosFromResultSet(ResultSet rs) throws SQLException {
ArrayList<Ingreso> ingresosList = new ArrayList<>();
while (rs.next()) {
int tipoIngresoId = rs.getInt("tipo_ingreso_id");
TipoIngresoDAO tipoEgresoDAO = new SQLiteTipoIngresoDAO();
TipoIngreso tipoIngreso = tipoEgresoDAO.findById(tipoIngresoId).get(0);
int cajaId = rs.getInt("caja_id");
CajaDAO cajaDAO = new SQLiteCajaDAO();
Caja caja = cajaDAO.getById(cajaId).get();
Ingreso ingreso = new Ingreso();
ingreso.setId(rs.getInt("id"));
ingreso.setValor(rs.getInt("valor"));
ingreso.setNroZInicial(rs.getString("nro_z_inicial"));
ingreso.setNroZFinal(rs.getString("nro_z_final"));
ingreso.setNroInicial(rs.getString("nro_inicial"));
ingreso.setNroFinal(rs.getString("nro_final"));
ingreso.setTipoIngreso(tipoIngreso);
ingreso.setCaja(caja);
LOGGER.log(Level.FINER, "Se a creado: {0}", ingreso);
ingresosList.add(ingreso);
}
return ingresosList;
}
}