La palaba get es mas bonita que find
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user