La palaba get es mas bonita que find

This commit is contained in:
Daniel Cortes
2019-03-07 16:16:01 -03:00
parent b6021c82d7
commit 9c0765b81f
8 changed files with 100 additions and 100 deletions

View File

@@ -75,7 +75,7 @@ public class ArqueoController extends BaseController {
* Rellena los campos del efectivo con la instancia de efectivo que pertenece a la caja
*/
private void fillEfectivo() {
this.efectivo = DAOManager.getEfectivoDAO().findByCaja(this.caja).orElse(Efectivo.EMPTY);
this.efectivo = DAOManager.getEfectivoDAO().getByCaja(this.caja).orElse(Efectivo.EMPTY);
this.view.getVeinteMilField().setValue(efectivo.getVeinteMil());
this.view.getDiezMilField().setValue(efectivo.getDiezMil());
this.view.getCincoMilField().setValue(efectivo.getCincoMil());
@@ -91,7 +91,7 @@ public class ArqueoController extends BaseController {
* Rellea los campos de documentos con la instancia de documentos que pertenece a la caja
*/
private void fillDocumentos() {
this.documentos = DAOManager.getDocumentosDAO().findByCaja(caja).orElse(Documentos.EMPTY);
this.documentos = DAOManager.getDocumentosDAO().getByCaja(caja).orElse(Documentos.EMPTY);
this.view.getTarjetasField().setValue(documentos.getTarjetas());
this.view.getChequesField().setValue(documentos.getCheques());
this.view.getRetiroField().setValue(documentos.getRetiros());

View File

@@ -33,7 +33,7 @@ public class CalcularFondoController extends BaseController {
private void fillTable() {
FondoTableModel tableModel = this.view.getTableModel();
tableModel.removeRows();
for (CalculoFondo calculoFondo : DAOManager.getCalculoFondoDAO().findByCaja(this.caja)) {
for (CalculoFondo calculoFondo : DAOManager.getCalculoFondoDAO().getByCaja(this.caja)) {
tableModel.addRow(calculoFondo);
}
}

View File

@@ -30,18 +30,17 @@ import java.util.Optional;
public interface CalculoFondoDAO {
List<CalculoFondo> findAll();
List<CalculoFondo> getAll();
List<CalculoFondo> findByCaja(Caja caja);
List<CalculoFondo> getByCaja(Caja caja);
Optional<CalculoFondo> findById(int id);
Optional<CalculoFondo> getById(int id);
int getTotalCalculoFondo(Caja caja);
void insertCalculoFondo(CalculoFondo calculoFondo);
void updateCalculoFondo(CalculoFondo calculoFondo);
void deleteCalculoFondo(CalculoFondo calculoFondo);
int getTotalCalculoFondo(Caja caja);
}

View File

@@ -49,7 +49,7 @@ public class SQLiteCalculoFondoDAO implements CalculoFondoDAO {
}
@Override
public List<CalculoFondo> findAll() {
public List<CalculoFondo> getAll() {
List<CalculoFondo> calculoFondoList = new ArrayList<>();
String query = "select * from calculo_fondo";
try (Connection conn = connectionHolder.getConnection()) {
@@ -79,7 +79,7 @@ public class SQLiteCalculoFondoDAO implements CalculoFondoDAO {
}
@Override
public List<CalculoFondo> findByCaja(Caja caja) {
public List<CalculoFondo> getByCaja(Caja caja) {
List<CalculoFondo> calculoFondoList = new ArrayList<>();
if(Caja.EMPTY == caja){
return calculoFondoList;
@@ -111,7 +111,7 @@ public class SQLiteCalculoFondoDAO implements CalculoFondoDAO {
}
@Override
public Optional<CalculoFondo> findById(int id) {
public Optional<CalculoFondo> getById(int id) {
CalculoFondo calculoFondo = null;
String query = "select * from calculo_fondo where id = ?";
try (Connection conn = connectionHolder.getConnection()) {
@@ -138,6 +138,33 @@ public class SQLiteCalculoFondoDAO implements CalculoFondoDAO {
return Optional.ofNullable(calculoFondo);
}
@Override
public int getTotalCalculoFondo(Caja caja) {
int sum = 0;
if (Caja.EMPTY == caja) {
return sum;
}
String query = "select sum(valor) from calculo_fondo where caja_id = ?";
try (Connection conn = connectionHolder.getConnection()) {
try (PreparedStatement ps = conn.prepareStatement(query)) {
ps.setInt(1, caja.getId());
try (ResultSet rs = ps.executeQuery()) {
LOGGER.log(Level.FINE, "QUERY: {0} | values: {1}", new Object[]{query, caja.getId()});
if (rs.next()) {
sum = rs.getInt(1);
}
}
}
} catch (SQLException e) {
LOGGER.log(Level.SEVERE, e.toString(), e);
}
return sum;
}
@Override
public void insertCalculoFondo(CalculoFondo calculoFondo) {
String query = "insert into calculo_fondo (valor, descripcion, caja_id) values (?, ?, ?)";
@@ -192,32 +219,4 @@ public class SQLiteCalculoFondoDAO implements CalculoFondoDAO {
LOGGER.log(Level.SEVERE, e.toString(), e);
}
}
@Override
public int getTotalCalculoFondo(Caja caja) {
int sum = 0;
if (Caja.EMPTY == caja) {
return sum;
}
String query = "select sum(valor) from calculo_fondo where caja_id = ?";
try (Connection conn = connectionHolder.getConnection()) {
try (PreparedStatement ps = conn.prepareStatement(query)) {
ps.setInt(1, caja.getId());
try (ResultSet rs = ps.executeQuery()) {
LOGGER.log(Level.FINE, "QUERY: {0} | values: {1}", new Object[]{query, caja.getId()});
if (rs.next()) {
sum = rs.getInt(1);
}
}
}
} catch (SQLException e) {
LOGGER.log(Level.SEVERE, e.toString(), e);
}
return sum;
}
}

View File

@@ -30,11 +30,13 @@ import java.util.Optional;
public interface DocumentosDAO {
List<Documentos> findAll();
List<Documentos> getAll();
Optional<Documentos> findById(int id);
Optional<Documentos> getById(int id);
Optional<Documentos> findByCaja(Caja caja);
Optional<Documentos> getByCaja(Caja caja);
int getTotalDocumentos(Caja caja);
void insertDocumentos(Documentos documentos);
@@ -43,7 +45,4 @@ public interface DocumentosDAO {
void updateDocumentos(Documentos documentos);
void deleteDocumentos(Documentos documentos);
int getTotalDocumentos(Caja caja);
}

View File

@@ -49,7 +49,7 @@ public class SQLiteDocumentosDAO implements DocumentosDAO {
}
@Override
public List<Documentos> findAll() {
public List<Documentos> getAll() {
List<Documentos> documentosList = new ArrayList<>();
String query = "select * from documentos";
try (Connection conn = connectionHolder.getConnection()) {
@@ -80,7 +80,7 @@ public class SQLiteDocumentosDAO implements DocumentosDAO {
}
@Override
public Optional<Documentos> findById(int id) {
public Optional<Documentos> getById(int id) {
Documentos documentos = null;
try (Connection conn = connectionHolder.getConnection()) {
@@ -111,7 +111,7 @@ public class SQLiteDocumentosDAO implements DocumentosDAO {
}
@Override
public Optional<Documentos> findByCaja(Caja caja) {
public Optional<Documentos> getByCaja(Caja caja) {
Documentos documentos = null;
if (Caja.EMPTY == caja) {
@@ -141,6 +141,29 @@ public class SQLiteDocumentosDAO implements DocumentosDAO {
return Optional.ofNullable(documentos);
}
@Override
public int getTotalDocumentos(Caja caja) {
int total = 0;
if (Caja.EMPTY == caja) {
return total;
}
String query = "select cheques + tarjetas + retiros from documentos where caja_id = ?";
try (Connection conn = connectionHolder.getConnection()) {
try (PreparedStatement ps = conn.prepareStatement(query)) {
ps.setInt(1, caja.getId());
try (ResultSet rs = ps.executeQuery()) {
if (rs.next()) {
total = rs.getInt(1);
}
}
}
} catch (SQLException e) {
LOGGER.log(Level.SEVERE, e.toString(), e);
}
return total;
}
@Override
public void insertDocumentos(Documentos documentos) {
String query = "insert into documentos (cheques, tarjetas, retiros, caja_id) values (?,?,?,?)";
@@ -213,26 +236,4 @@ public class SQLiteDocumentosDAO implements DocumentosDAO {
}
}
@Override
public int getTotalDocumentos(Caja caja) {
int total = 0;
if (Caja.EMPTY == caja) {
return total;
}
String query = "select cheques + tarjetas + retiros from documentos where caja_id = ?";
try (Connection conn = connectionHolder.getConnection()) {
try (PreparedStatement ps = conn.prepareStatement(query)) {
ps.setInt(1, caja.getId());
try (ResultSet rs = ps.executeQuery()) {
if (rs.next()) {
total = rs.getInt(1);
}
}
}
} catch (SQLException e) {
LOGGER.log(Level.SEVERE, e.toString(), e);
}
return total;
}
}

View File

@@ -30,11 +30,13 @@ import java.util.Optional;
public interface EfectivoDAO {
List<Efectivo> findAll();
List<Efectivo> getAll();
Optional<Efectivo> findById(int id);
Optional<Efectivo> getById(int id);
Optional<Efectivo> findByCaja(Caja caja);
Optional<Efectivo> getByCaja(Caja caja);
int getTotalEfectivo(Caja caja);
void insertEfectivo(Efectivo efectivo);
@@ -44,5 +46,4 @@ public interface EfectivoDAO {
void deleteEfectivo(Efectivo efectivo);
int getTotalEfectivo(Caja caja);
}

View File

@@ -49,7 +49,7 @@ public class SQLiteEfectivoDAO implements EfectivoDAO {
}
@Override
public List<Efectivo> findAll() {
public List<Efectivo> getAll() {
List<Efectivo> efectivoList = new ArrayList<>();
String query = "select * from efectivos";
try (Connection conn = connectionHolder.getConnection()) {
@@ -86,7 +86,7 @@ public class SQLiteEfectivoDAO implements EfectivoDAO {
}
@Override
public Optional<Efectivo> findById(int id) {
public Optional<Efectivo> getById(int id) {
Efectivo efectivo = null;
String query = "select * from efectivos where id = ?";
try (Connection conn = connectionHolder.getConnection()) {
@@ -122,7 +122,7 @@ public class SQLiteEfectivoDAO implements EfectivoDAO {
}
@Override
public Optional<Efectivo> findByCaja(Caja caja) {
public Optional<Efectivo> getByCaja(Caja caja) {
Efectivo efectivo = null;
if (Caja.EMPTY == caja) {
return Optional.ofNullable(efectivo);
@@ -156,6 +156,29 @@ public class SQLiteEfectivoDAO implements EfectivoDAO {
return Optional.ofNullable(efectivo);
}
@Override
public int getTotalEfectivo(Caja caja) {
int total = 0;
if (Caja.EMPTY == caja) {
return total;
}
String query = "select veinte_mil + diez_mil + cinco_mil + dos_mil + mil + quinientos + cien + cincuenta + diez from efectivos where caja_id = ?";
try (Connection conn = connectionHolder.getConnection()) {
try (PreparedStatement ps = conn.prepareStatement(query)) {
ps.setInt(1, caja.getId());
try (ResultSet rs = ps.executeQuery()) {
if (rs.next()) {
total = rs.getInt(1);
}
}
}
} catch (SQLException e) {
LOGGER.log(Level.SEVERE, e.toString(), e);
}
return total;
}
@Override
public void insertEfectivo(Efectivo efectivo) {
String query = "insert into efectivos (veinte_mil, diez_mil, cinco_mil, dos_mil, mil, quinientos, cien, cincuenta, diez, caja_id) values (?,?,?,?,?,?,?,?,?,?)";
@@ -240,26 +263,4 @@ public class SQLiteEfectivoDAO implements EfectivoDAO {
}
}
@Override
public int getTotalEfectivo(Caja caja) {
int total = 0;
if (Caja.EMPTY == caja) {
return total;
}
String query = "select veinte_mil + diez_mil + cinco_mil + dos_mil + mil + quinientos + cien + cincuenta + diez from efectivos where caja_id = ?";
try (Connection conn = connectionHolder.getConnection()) {
try (PreparedStatement ps = conn.prepareStatement(query)) {
ps.setInt(1, caja.getId());
try (ResultSet rs = ps.executeQuery()) {
if (rs.next()) {
total = rs.getInt(1);
}
}
}
} catch (SQLException e) {
LOGGER.log(Level.SEVERE, e.toString(), e);
}
return total;
}
}