se ejecuto limpieza del codigo, reformateo del codigo y optimizacion de los imports por parte del IDE
This commit is contained in:
@@ -41,15 +41,14 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SQLiteCajaDAO extends CajaDAO {
|
||||
public SQLiteCajaDAO () {
|
||||
public SQLiteCajaDAO() {
|
||||
this.connectionHolder = new SQLiteConnectionHolder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Caja> findAll() {
|
||||
List<Caja> cajaList = new ArrayList<>();
|
||||
try {
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
try (Connection conn = connectionHolder.getConnection()) {
|
||||
PreparedStatement ps = conn.prepareStatement("select * from caja");
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
@@ -57,18 +56,17 @@ public class SQLiteCajaDAO extends CajaDAO {
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return cajaList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Caja findById(int id) {
|
||||
Caja caja = null;
|
||||
try {
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
try (Connection conn = connectionHolder.getConnection()) {
|
||||
PreparedStatement ps = conn.prepareStatement("select * from caja where id = ?");
|
||||
|
||||
ps.setInt(1, id);
|
||||
@@ -79,7 +77,6 @@ public class SQLiteCajaDAO extends CajaDAO {
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -89,8 +86,7 @@ public class SQLiteCajaDAO extends CajaDAO {
|
||||
@Override
|
||||
public Caja findByFecha(LocalDate fecha) {
|
||||
Caja caja = null;
|
||||
try {
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
try (Connection conn = connectionHolder.getConnection()) {
|
||||
PreparedStatement ps = conn.prepareStatement("select * from caja where fecha = ?");
|
||||
|
||||
ps.setString(1, fecha.toString());
|
||||
@@ -99,13 +95,12 @@ public class SQLiteCajaDAO extends CajaDAO {
|
||||
|
||||
List<Caja> cajaList = this.cajasFromResultSet(rs);
|
||||
|
||||
if(cajaList.size() > 0){
|
||||
if (cajaList.size() > 0) {
|
||||
caja = cajaList.get(0);
|
||||
}
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -115,8 +110,7 @@ public class SQLiteCajaDAO extends CajaDAO {
|
||||
@Override
|
||||
public boolean insertCaja(Caja caja) {
|
||||
int updates;
|
||||
try {
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
try (Connection conn = connectionHolder.getConnection()) {
|
||||
PreparedStatement ps = conn.prepareStatement("insert into caja (fecha) values (?)");
|
||||
|
||||
ps.setString(1, caja.getFecha().toString());
|
||||
@@ -131,7 +125,6 @@ public class SQLiteCajaDAO extends CajaDAO {
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
@@ -142,8 +135,7 @@ public class SQLiteCajaDAO extends CajaDAO {
|
||||
@Override
|
||||
public boolean updateCaja(Caja caja) {
|
||||
int updates;
|
||||
try {
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
try (Connection conn = connectionHolder.getConnection()) {
|
||||
PreparedStatement ps = conn.prepareStatement("update caja set fecha = ? where id = ?");
|
||||
ps.setString(1, caja.getFecha().toString());
|
||||
ps.setInt(2, caja.getId());
|
||||
@@ -151,7 +143,6 @@ public class SQLiteCajaDAO extends CajaDAO {
|
||||
updates = ps.executeUpdate();
|
||||
|
||||
ps.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
@@ -164,8 +155,8 @@ public class SQLiteCajaDAO extends CajaDAO {
|
||||
LocalDate date = month.withDayOfMonth(1);
|
||||
LocalDate endDate = date.withDayOfMonth(date.lengthOfMonth()).plusDays(1);
|
||||
|
||||
while(date.isBefore(endDate)) {
|
||||
if(this.findByFecha(date) != null){
|
||||
while (date.isBefore(endDate)) {
|
||||
if (this.findByFecha(date) != null) {
|
||||
date = date.plusDays(1);
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user