Mejorado el manejo del archivo properties respecto como se carga y lee en el resto de clases
la clase responsable cambio de nombre a configuration y ahora tiene un bloque estatico que inicializa el objeto properties y expone el get de este objeto
This commit is contained in:
839
.idea/workspace.xml
generated
839
.idea/workspace.xml
generated
File diff suppressed because it is too large
Load Diff
BIN
dist/Programa Caja.jar
vendored
BIN
dist/Programa Caja.jar
vendored
Binary file not shown.
7
dist/conf.properties
vendored
7
dist/conf.properties
vendored
@@ -4,16 +4,11 @@
|
||||
|
||||
# database_type sirve para elegir el sistema de base de datos que utilizara el sistema.
|
||||
# los valores soportados son:
|
||||
# - mysql
|
||||
# - sqlite
|
||||
|
||||
#database_type = mysql
|
||||
database_type = sqlite
|
||||
|
||||
# database_uri es la uri de la base de datos con la que se conectara el sistema.
|
||||
# debe corresponder con el sistema de base de datos seleccionado en database_type
|
||||
# por ahora soporte solo a sqlite asi que debe ser la uri correspondiente
|
||||
|
||||
#database_uri = jdbc:mysql://localhost/caja?user=root&password=lagging&useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC
|
||||
database_uri = jdbc:sqlite:rodriguez.dat
|
||||
|
||||
|
||||
|
||||
@@ -25,29 +25,23 @@
|
||||
package danielcortes.xyz;
|
||||
|
||||
import danielcortes.xyz.controllers.ManagerController;
|
||||
import danielcortes.xyz.data.Properties;
|
||||
import danielcortes.xyz.data.Configuration;
|
||||
import danielcortes.xyz.models.caja.CajaDAO;
|
||||
import danielcortes.xyz.models.caja.MysqlCajaDAO;
|
||||
import danielcortes.xyz.models.caja.SQLiteCajaDAO;
|
||||
import danielcortes.xyz.models.documentos.DocumentosDAO;
|
||||
import danielcortes.xyz.models.documentos.MysqlDocumentosDAO;
|
||||
import danielcortes.xyz.models.documentos.SQLiteDocumentosDAO;
|
||||
import danielcortes.xyz.models.efectivo.EfectivoDAO;
|
||||
import danielcortes.xyz.models.efectivo.MysqlEfectivoDAO;
|
||||
import danielcortes.xyz.models.efectivo.SQLiteEfectivoDAO;
|
||||
import danielcortes.xyz.models.egreso.EgresoDAO;
|
||||
import danielcortes.xyz.models.egreso.MysqlEgresoDAO;
|
||||
import danielcortes.xyz.models.egreso.SQLiteEgresoDAO;
|
||||
import danielcortes.xyz.models.ingreso.IngresoDAO;
|
||||
import danielcortes.xyz.models.ingreso.MysqlIngresoDAO;
|
||||
import danielcortes.xyz.models.ingreso.SQLiteIngresoDAO;
|
||||
import danielcortes.xyz.models.tipo_egreso.MysqlTipoEgresoDAO;
|
||||
import danielcortes.xyz.models.tipo_egreso.SQLiteTipoEgresoDAO;
|
||||
import danielcortes.xyz.models.tipo_egreso.TipoEgresoDAO;
|
||||
import danielcortes.xyz.models.tipo_ingreso.MysqlTipoIngresoDAO;
|
||||
import danielcortes.xyz.models.tipo_ingreso.SQLiteTipoIngresoDAO;
|
||||
import danielcortes.xyz.models.tipo_ingreso.TipoIngresoDAO;
|
||||
import danielcortes.xyz.views.ManagerView;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.Locale;
|
||||
|
||||
@@ -61,7 +55,7 @@ public class Main {
|
||||
System.setProperty("swing.aatext", "true");
|
||||
|
||||
try {
|
||||
UIManager.setLookAndFeel(Properties.getInstance().getProperty("look_and_feel"));
|
||||
UIManager.setLookAndFeel(Configuration.get("look_and_feel"));
|
||||
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -69,36 +63,18 @@ public class Main {
|
||||
Locale.setDefault(new Locale("es"));
|
||||
|
||||
|
||||
CajaDAO cajaDAO = null;
|
||||
DocumentosDAO documentosDAO = null;
|
||||
EfectivoDAO efectivoDAO = null;
|
||||
EgresoDAO egresoDAO = null;
|
||||
IngresoDAO ingresoDAO = null;
|
||||
TipoEgresoDAO tipoEgresoDAO = null;
|
||||
TipoIngresoDAO tipoIngresoDAO = null;
|
||||
|
||||
if (Properties.getInstance().getProperty("database_type").equals("mysql")) {
|
||||
cajaDAO = new MysqlCajaDAO();
|
||||
documentosDAO = new MysqlDocumentosDAO();
|
||||
efectivoDAO = new MysqlEfectivoDAO();
|
||||
egresoDAO = new MysqlEgresoDAO();
|
||||
ingresoDAO = new MysqlIngresoDAO();
|
||||
tipoEgresoDAO = new MysqlTipoEgresoDAO();
|
||||
tipoIngresoDAO = new MysqlTipoIngresoDAO();
|
||||
} else if (Properties.getInstance().getProperty("database_type").equals("sqlite")) {
|
||||
cajaDAO = new SQLiteCajaDAO();
|
||||
documentosDAO = new SQLiteDocumentosDAO();
|
||||
efectivoDAO = new SQLiteEfectivoDAO();
|
||||
egresoDAO = new SQLiteEgresoDAO();
|
||||
ingresoDAO = new SQLiteIngresoDAO();
|
||||
tipoEgresoDAO = new SQLiteTipoEgresoDAO();
|
||||
tipoIngresoDAO = new SQLiteTipoIngresoDAO();
|
||||
}
|
||||
CajaDAO cajaDAO = new SQLiteCajaDAO();
|
||||
DocumentosDAO documentosDAO = new SQLiteDocumentosDAO();
|
||||
EfectivoDAO efectivoDAO = new SQLiteEfectivoDAO();
|
||||
EgresoDAO egresoDAO = new SQLiteEgresoDAO();
|
||||
IngresoDAO ingresoDAO = new SQLiteIngresoDAO();
|
||||
TipoEgresoDAO tipoEgresoDAO = new SQLiteTipoEgresoDAO();
|
||||
TipoIngresoDAO tipoIngresoDAO = new SQLiteTipoIngresoDAO();
|
||||
|
||||
ManagerView view = new ManagerView();
|
||||
ManagerController managerController = new ManagerController(view, cajaDAO, documentosDAO, efectivoDAO, egresoDAO, ingresoDAO, tipoEgresoDAO, tipoIngresoDAO);
|
||||
|
||||
JFrame frame = new JFrame("Caja: " + Properties.getInstance().getProperty("nombre_caja"));
|
||||
JFrame frame = new JFrame("Caja: " + Configuration.get("nombre_caja"));
|
||||
frame.setContentPane(view.getContentPanel());
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package danielcortes.xyz.controllers;
|
||||
|
||||
import danielcortes.xyz.controllers.actions.NextAction;
|
||||
import danielcortes.xyz.data.Properties;
|
||||
import danielcortes.xyz.data.Configuration;
|
||||
import danielcortes.xyz.models.caja.Caja;
|
||||
import danielcortes.xyz.models.calculo_fondo.CalculoFondo;
|
||||
import danielcortes.xyz.models.calculo_fondo.CalculoFondoDAO;
|
||||
@@ -37,7 +37,7 @@ public class CalcularFondoController {
|
||||
}
|
||||
|
||||
private void showView() {
|
||||
JFrame frame = new JFrame("Calculo de Fondo: " + Properties.getInstance().getProperty("nombre_caja"));
|
||||
JFrame frame = new JFrame("Calculo de Fondo: " + Configuration.get("nombre_caja"));
|
||||
frame.setContentPane(view.getContentPanel());
|
||||
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
frame.pack();
|
||||
|
||||
@@ -28,22 +28,14 @@ import danielcortes.xyz.models.caja.Caja;
|
||||
import danielcortes.xyz.models.caja.CajaDAO;
|
||||
import danielcortes.xyz.models.documentos.Documentos;
|
||||
import danielcortes.xyz.models.documentos.DocumentosDAO;
|
||||
import danielcortes.xyz.models.documentos.MysqlDocumentosDAO;
|
||||
import danielcortes.xyz.models.efectivo.Efectivo;
|
||||
import danielcortes.xyz.models.efectivo.EfectivoDAO;
|
||||
import danielcortes.xyz.models.efectivo.MysqlEfectivoDAO;
|
||||
import danielcortes.xyz.models.egreso.EgresoDAO;
|
||||
import danielcortes.xyz.models.ingreso.IngresoDAO;
|
||||
import danielcortes.xyz.models.ingreso.MysqlIngresoDAO;
|
||||
import danielcortes.xyz.models.tipo_egreso.TipoEgresoDAO;
|
||||
import danielcortes.xyz.models.egreso.MysqlEgresoDAO;
|
||||
import danielcortes.xyz.models.tipo_egreso.MysqlTipoEgresoDAO;
|
||||
import danielcortes.xyz.models.tipo_ingreso.MysqlTipoIngresoDAO;
|
||||
import danielcortes.xyz.models.tipo_ingreso.TipoIngreso;
|
||||
import danielcortes.xyz.models.tipo_ingreso.TipoIngresoDAO;
|
||||
import danielcortes.xyz.views.*;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.time.LocalDate;
|
||||
|
||||
|
||||
@@ -26,27 +26,26 @@ package danielcortes.xyz.data;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Properties;
|
||||
|
||||
public class Properties {
|
||||
private static Properties ourInstance = new Properties();
|
||||
public static java.util.Properties getInstance() {
|
||||
return ourInstance.props;
|
||||
}
|
||||
public class Configuration {
|
||||
private static final Properties config;
|
||||
|
||||
private java.util.Properties props;
|
||||
static {
|
||||
config = new Properties();
|
||||
|
||||
private Properties() {
|
||||
try {
|
||||
this.props = new java.util.Properties();
|
||||
FileInputStream in = new FileInputStream("conf.properties");
|
||||
this.props.load(in);
|
||||
config.load(in);
|
||||
in.close();
|
||||
} catch (IOException e) {
|
||||
System.err.println("Couldn't load properties");
|
||||
System.err.println("Couldn't load properties! The application will close");
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static String get(String key){
|
||||
return config.getProperty(key);
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* 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.data;
|
||||
|
||||
import java.sql.*;
|
||||
|
||||
public class MysqlConnectionHolder implements ConnectionHolder {
|
||||
private String databaseURI;
|
||||
public MysqlConnectionHolder(){
|
||||
this.databaseURI = Properties.getInstance().getProperty("database_uri");
|
||||
}
|
||||
|
||||
public java.sql.Connection getConnection() throws SQLException{
|
||||
return DriverManager.getConnection(databaseURI);
|
||||
}
|
||||
}
|
||||
@@ -24,17 +24,19 @@
|
||||
|
||||
package danielcortes.xyz.data;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class SQLiteConnectionHolder implements ConnectionHolder {
|
||||
private String databaseURI;
|
||||
public SQLiteConnectionHolder(){
|
||||
this.databaseURI = Properties.getInstance().getProperty("database_uri");
|
||||
|
||||
public SQLiteConnectionHolder() {
|
||||
this.databaseURI = Configuration.get("database_uri");
|
||||
}
|
||||
|
||||
@Override
|
||||
public java.sql.Connection getConnection() throws SQLException{
|
||||
public Connection getConnection() throws SQLException {
|
||||
try {
|
||||
Class.forName("org.sqlite.JDBC");
|
||||
} catch (ClassNotFoundException e) {
|
||||
|
||||
@@ -1,190 +0,0 @@
|
||||
/*
|
||||
* 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.caja;
|
||||
|
||||
import danielcortes.xyz.data.MysqlConnectionHolder;
|
||||
import danielcortes.xyz.models.documentos.Documentos;
|
||||
import danielcortes.xyz.models.documentos.DocumentosDAO;
|
||||
import danielcortes.xyz.models.documentos.MysqlDocumentosDAO;
|
||||
import danielcortes.xyz.models.documentos.SQLiteDocumentosDAO;
|
||||
import danielcortes.xyz.models.efectivo.Efectivo;
|
||||
import danielcortes.xyz.models.efectivo.EfectivoDAO;
|
||||
import danielcortes.xyz.models.efectivo.MysqlEfectivoDAO;
|
||||
import danielcortes.xyz.models.efectivo.SQLiteEfectivoDAO;
|
||||
|
||||
import java.sql.*;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MysqlCajaDAO extends CajaDAO {
|
||||
|
||||
public MysqlCajaDAO() {
|
||||
this.connectionHolder = new MysqlConnectionHolder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Caja> findAll() {
|
||||
List<Caja> cajaList = new ArrayList<>();
|
||||
try {
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("select * from caja");
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
cajaList = this.cajasFromResultSet(rs);
|
||||
|
||||
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();
|
||||
PreparedStatement ps = conn.prepareStatement("select * from caja where id = ?");
|
||||
|
||||
ps.setInt(1, id);
|
||||
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
caja = this.cajasFromResultSet(rs).get(0);
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return caja;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Caja findByFecha(LocalDate fecha) {
|
||||
Caja caja = null;
|
||||
try {
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("select * from caja where fecha = ?");
|
||||
|
||||
ps.setObject(1, fecha);
|
||||
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
List<Caja> cajaList = this.cajasFromResultSet(rs);
|
||||
|
||||
if (cajaList.size() > 0) {
|
||||
caja = cajaList.get(0);
|
||||
}
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return caja;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean insertCaja(Caja caja) {
|
||||
int updates;
|
||||
try {
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("insert into caja (fecha) values (?)");
|
||||
ps.setObject(1, caja.getFecha());
|
||||
|
||||
updates = ps.executeUpdate();
|
||||
ps.close();
|
||||
|
||||
ps = conn.prepareStatement("select last_insert_id()");
|
||||
ResultSet rs = ps.executeQuery();
|
||||
rs.next();
|
||||
caja.setId(rs.getInt(1));
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return updates > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateCaja(Caja caja) {
|
||||
int updates;
|
||||
try {
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("update caja set fecha = ? where id = ?");
|
||||
ps.setObject(1, caja.getFecha());
|
||||
ps.setInt(2, caja.getId());
|
||||
|
||||
updates = ps.executeUpdate();
|
||||
|
||||
ps.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return updates > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createCajasForMonth(LocalDate month) {
|
||||
LocalDate date = month.withDayOfMonth(1);
|
||||
LocalDate endDate = date.withDayOfMonth(date.lengthOfMonth());
|
||||
|
||||
while(date.isBefore(endDate)) {
|
||||
if(this.findByFecha(date) != null){
|
||||
date = date.plusDays(1);
|
||||
continue;
|
||||
}
|
||||
|
||||
Caja caja = new Caja();
|
||||
caja.setFecha(date);
|
||||
this.insertCaja(caja);
|
||||
|
||||
Efectivo efectivo = new Efectivo();
|
||||
EfectivoDAO efectivoDAO = new MysqlEfectivoDAO();
|
||||
efectivo.setCaja(caja);
|
||||
efectivoDAO.insertDefaultEfectivo(efectivo);
|
||||
|
||||
Documentos documentos = new Documentos();
|
||||
DocumentosDAO documentosDAO = new MysqlDocumentosDAO();
|
||||
documentos.setCaja(caja);
|
||||
documentosDAO.insertDefaultDocumentos(documentos);
|
||||
|
||||
date = date.plusDays(1);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -25,10 +25,9 @@
|
||||
package danielcortes.xyz.models.documentos;
|
||||
|
||||
import danielcortes.xyz.data.ConnectionHolder;
|
||||
import danielcortes.xyz.data.MysqlConnectionHolder;
|
||||
import danielcortes.xyz.models.caja.Caja;
|
||||
import danielcortes.xyz.models.caja.CajaDAO;
|
||||
import danielcortes.xyz.models.caja.MysqlCajaDAO;
|
||||
import danielcortes.xyz.models.caja.SQLiteCajaDAO;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
@@ -52,7 +51,7 @@ public abstract class DocumentosDAO {
|
||||
protected List<Documentos> documentosFromResultSet(ResultSet rs) throws SQLException {
|
||||
List<Documentos> documentosList = new ArrayList<>();
|
||||
while (rs.next()) {
|
||||
CajaDAO cajaDAO = new MysqlCajaDAO();
|
||||
CajaDAO cajaDAO = new SQLiteCajaDAO();
|
||||
Caja caja = cajaDAO.findById(rs.getInt("caja_id"));
|
||||
|
||||
Documentos documentos = new Documentos();
|
||||
|
||||
@@ -1,226 +0,0 @@
|
||||
/*
|
||||
* 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.documentos;
|
||||
|
||||
import danielcortes.xyz.data.MysqlConnectionHolder;
|
||||
import danielcortes.xyz.models.caja.Caja;
|
||||
import danielcortes.xyz.models.caja.CajaDAO;
|
||||
import danielcortes.xyz.models.caja.MysqlCajaDAO;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MysqlDocumentosDAO extends DocumentosDAO {
|
||||
|
||||
public MysqlDocumentosDAO() {
|
||||
this.connectionHolder = new MysqlConnectionHolder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Documentos> findAll() {
|
||||
List<Documentos> documentosList = new ArrayList<>();
|
||||
try {
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("select * from documentos");
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
documentosList = this.documentosFromResultSet(rs);
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return documentosList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Documentos findById(int id) {
|
||||
Documentos documentos = null;
|
||||
try {
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("select * from documentos where id = ?");
|
||||
ps.setInt(1, id);
|
||||
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
List<Documentos> documentosList = this.documentosFromResultSet(rs);
|
||||
if(documentosList.size() > 0){
|
||||
documentos = documentosList.get(0);
|
||||
}
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return documentos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Documentos findByCaja(Caja caja) {
|
||||
Documentos documentos = null;
|
||||
try {
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("select * from documentos where caja_id = ?");
|
||||
ps.setInt(1, caja.getId());
|
||||
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
List<Documentos> documentosList = this.documentosFromResultSet(rs);
|
||||
if(documentosList.size() > 0){
|
||||
documentos = documentosList.get(0);
|
||||
}
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return documentos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean insertDocumentos(Documentos documentos) {
|
||||
int updates;
|
||||
try {
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("insert into documentos (cheques, tarjetas, caja_id) values (?,?,?)");
|
||||
ps.setInt(1, documentos.getCheques());
|
||||
ps.setInt(2, documentos.getTarjetas());
|
||||
ps.setInt(3, documentos.getCaja().getId());
|
||||
|
||||
updates = ps.executeUpdate();
|
||||
ps.close();
|
||||
|
||||
ps = conn.prepareStatement("select last_insert_id()");
|
||||
ResultSet rs = ps.executeQuery();
|
||||
rs.next();
|
||||
documentos.setId(rs.getInt(1));
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return updates > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean insertDefaultDocumentos(Documentos documentos) {
|
||||
int updates;
|
||||
try {
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("insert into documentos (cheques, tarjetas, caja_id) values (0,0,?)");
|
||||
ps.setInt(1, documentos.getCaja().getId());
|
||||
|
||||
updates = ps.executeUpdate();
|
||||
ps.close();
|
||||
|
||||
ps = conn.prepareStatement("select last_insert_id()");
|
||||
ResultSet rs = ps.executeQuery();
|
||||
rs.next();
|
||||
documentos.setId(rs.getInt(1));
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return updates > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateDocumentos(Documentos documentos) {
|
||||
int updates;
|
||||
try {
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("update documentos set tarjetas = ?, cheques = ?, caja_id = ? where id = ?");
|
||||
ps.setInt(1, documentos.getTarjetas());
|
||||
ps.setInt(2, documentos.getCheques());
|
||||
ps.setInt(3, documentos.getCaja().getId());
|
||||
ps.setInt(4, documentos.getId());
|
||||
updates = ps.executeUpdate();
|
||||
|
||||
ps.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return updates > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteDocumentos(Documentos documentos) {
|
||||
int updates;
|
||||
try {
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("delete from documentos where id = ?");
|
||||
ps.setInt(1, documentos.getId());
|
||||
|
||||
updates = ps.executeUpdate();
|
||||
|
||||
ps.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return updates > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTotalDocumentos(Caja caja) {
|
||||
int total = 0;
|
||||
try {
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("select cheques + tarjetas from documentos where caja_id = ?");
|
||||
ps.setInt(1, caja.getId());
|
||||
|
||||
ResultSet rs = ps.executeQuery();
|
||||
rs.next();
|
||||
total = rs.getInt(1);
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return total;
|
||||
}
|
||||
}
|
||||
@@ -25,10 +25,9 @@
|
||||
package danielcortes.xyz.models.efectivo;
|
||||
|
||||
import danielcortes.xyz.data.ConnectionHolder;
|
||||
import danielcortes.xyz.data.MysqlConnectionHolder;
|
||||
import danielcortes.xyz.models.caja.Caja;
|
||||
import danielcortes.xyz.models.caja.CajaDAO;
|
||||
import danielcortes.xyz.models.caja.MysqlCajaDAO;
|
||||
import danielcortes.xyz.models.caja.SQLiteCajaDAO;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
@@ -52,7 +51,7 @@ public abstract class EfectivoDAO {
|
||||
protected List<Efectivo> efectivosFromResultSet(ResultSet rs) throws SQLException {
|
||||
List<Efectivo> efectivoList = new ArrayList<>();
|
||||
while (rs.next()) {
|
||||
CajaDAO cajaDAO = new MysqlCajaDAO();
|
||||
CajaDAO cajaDAO = new SQLiteCajaDAO();
|
||||
Caja caja = cajaDAO.findById(rs.getInt("caja_id"));
|
||||
|
||||
Efectivo efectivo = new Efectivo();
|
||||
|
||||
@@ -1,238 +0,0 @@
|
||||
/*
|
||||
* 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.efectivo;
|
||||
|
||||
import danielcortes.xyz.data.MysqlConnectionHolder;
|
||||
import danielcortes.xyz.models.caja.Caja;
|
||||
import danielcortes.xyz.models.caja.CajaDAO;
|
||||
import danielcortes.xyz.models.caja.MysqlCajaDAO;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MysqlEfectivoDAO extends EfectivoDAO {
|
||||
public MysqlEfectivoDAO() {
|
||||
this.connectionHolder = new MysqlConnectionHolder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Efectivo> findAll() {
|
||||
List<Efectivo> efectivoList = new ArrayList<>();
|
||||
try {
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("select * from efectivos");
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
efectivoList = this.efectivosFromResultSet(rs);
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return efectivoList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Efectivo findById(int id) {
|
||||
Efectivo efectivo = null;
|
||||
try {
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("select * from efectivos where id = ?");
|
||||
ps.setInt(1, id);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
efectivo = this.efectivosFromResultSet(rs).get(0);
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return efectivo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Efectivo findByCaja(Caja caja) {
|
||||
Efectivo efectivo = null;
|
||||
try {
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("select * from efectivos where caja_id = ?");
|
||||
ps.setInt(1, caja.getId());
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
List<Efectivo> efectivoList = this.efectivosFromResultSet(rs);
|
||||
if (efectivoList.size() > 0) {
|
||||
efectivo = efectivoList.get(0);
|
||||
}
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return efectivo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean insertEfectivo(Efectivo efectivo) {
|
||||
int updates;
|
||||
try {
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("insert into efectivos (veinte_mil, diez_mil, cinco_mil, dos_mil, mil, quinientos, cien, cincuenta, diez, caja_id) values (?,?,?,?,?,?,?,?,?,?)");
|
||||
ps.setInt(1, efectivo.getVeinteMil());
|
||||
ps.setInt(2, efectivo.getDiezMil());
|
||||
ps.setInt(3, efectivo.getCincoMil());
|
||||
ps.setInt(4, efectivo.getDosMil());
|
||||
ps.setInt(5, efectivo.getMil());
|
||||
ps.setInt(6, efectivo.getQuinientos());
|
||||
ps.setInt(7, efectivo.getCien());
|
||||
ps.setInt(8, efectivo.getCincuenta());
|
||||
ps.setInt(9, efectivo.getDiez());
|
||||
ps.setInt(10, efectivo.getCaja().getId());
|
||||
|
||||
updates = ps.executeUpdate();
|
||||
ps.close();
|
||||
|
||||
ps = conn.prepareStatement("select last_insert_id()");
|
||||
ResultSet rs = ps.executeQuery();
|
||||
rs.next();
|
||||
efectivo.setId(rs.getInt(1));
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return updates > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean insertDefaultEfectivo(Efectivo efectivo) {
|
||||
int updates;
|
||||
try {
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("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,?)");
|
||||
ps.setInt(1, efectivo.getCaja().getId());
|
||||
|
||||
updates = ps.executeUpdate();
|
||||
ps.close();
|
||||
|
||||
ps = conn.prepareStatement("select last_insert_id()");
|
||||
ResultSet rs = ps.executeQuery();
|
||||
rs.next();
|
||||
efectivo.setId(rs.getInt(1));
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return updates > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateEfectivo(Efectivo efectivo) {
|
||||
int updates;
|
||||
try {
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("update efectivos set veinte_mil = ?, diez_mil = ?, cinco_mil = ?, dos_mil = ?, mil = ?, quinientos = ?, cien = ?, cincuenta = ?, diez = ?, caja_id = ? where id = ?");
|
||||
ps.setInt(1, efectivo.getVeinteMil());
|
||||
ps.setInt(2, efectivo.getDiezMil());
|
||||
ps.setInt(3, efectivo.getCincoMil());
|
||||
ps.setInt(4, efectivo.getDosMil());
|
||||
ps.setInt(5, efectivo.getMil());
|
||||
ps.setInt(6, efectivo.getQuinientos());
|
||||
ps.setInt(7, efectivo.getCien());
|
||||
ps.setInt(8, efectivo.getCincuenta());
|
||||
ps.setInt(9, efectivo.getDiez());
|
||||
ps.setInt(10, efectivo.getCaja().getId());
|
||||
ps.setInt(11, efectivo.getId());
|
||||
|
||||
updates = ps.executeUpdate();
|
||||
|
||||
ps.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return updates > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteEfectivo(Efectivo efectivo) {
|
||||
int updates;
|
||||
try {
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("delete from efectivos where id = ?");
|
||||
ps.setInt(1, efectivo.getId());
|
||||
|
||||
updates = ps.executeUpdate();
|
||||
|
||||
ps.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return updates > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTotalEfectivo(Caja caja) {
|
||||
int total = 0;
|
||||
try {
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("select veinte_mil + diez_mil + cinco_mil + dos_mil + mil + quinientos + cien + cincuenta + diez from efectivos where caja_id = ?");
|
||||
ps.setInt(1, caja.getId());
|
||||
|
||||
ResultSet rs = ps.executeQuery();
|
||||
rs.next();
|
||||
total = rs.getInt(1);
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return total;
|
||||
}
|
||||
}
|
||||
@@ -27,9 +27,8 @@ package danielcortes.xyz.models.egreso;
|
||||
import danielcortes.xyz.data.ConnectionHolder;
|
||||
import danielcortes.xyz.models.caja.Caja;
|
||||
import danielcortes.xyz.models.caja.CajaDAO;
|
||||
import danielcortes.xyz.models.caja.MysqlCajaDAO;
|
||||
import danielcortes.xyz.models.egreso.Egreso;
|
||||
import danielcortes.xyz.models.tipo_egreso.MysqlTipoEgresoDAO;
|
||||
import danielcortes.xyz.models.caja.SQLiteCajaDAO;
|
||||
import danielcortes.xyz.models.tipo_egreso.SQLiteTipoEgresoDAO;
|
||||
import danielcortes.xyz.models.tipo_egreso.TipoEgreso;
|
||||
import danielcortes.xyz.models.tipo_egreso.TipoEgresoDAO;
|
||||
|
||||
@@ -57,11 +56,11 @@ public abstract class EgresoDAO {
|
||||
ArrayList<Egreso> egresoList = new ArrayList<>();
|
||||
while(rs.next()){
|
||||
int tipoEgresoId = rs.getInt("tipo_egreso_id");
|
||||
TipoEgresoDAO tipoEgresoDAO = new MysqlTipoEgresoDAO();
|
||||
TipoEgresoDAO tipoEgresoDAO = new SQLiteTipoEgresoDAO();
|
||||
TipoEgreso tipoEgreso = tipoEgresoDAO.findById(tipoEgresoId).get(0);
|
||||
|
||||
int cajaId = rs.getInt("caja_id");
|
||||
CajaDAO cajaDAO = new MysqlCajaDAO();
|
||||
CajaDAO cajaDAO = new SQLiteCajaDAO();
|
||||
Caja caja = cajaDAO.findById(cajaId);
|
||||
|
||||
Egreso egreso = new Egreso();
|
||||
|
||||
@@ -1,241 +0,0 @@
|
||||
/*
|
||||
* 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.egreso;
|
||||
|
||||
import danielcortes.xyz.data.MysqlConnectionHolder;
|
||||
import danielcortes.xyz.models.caja.Caja;
|
||||
import danielcortes.xyz.models.caja.CajaDAO;
|
||||
import danielcortes.xyz.models.caja.MysqlCajaDAO;
|
||||
import danielcortes.xyz.models.tipo_egreso.TipoEgreso;
|
||||
import danielcortes.xyz.models.tipo_egreso.TipoEgresoDAO;
|
||||
import danielcortes.xyz.models.tipo_egreso.MysqlTipoEgresoDAO;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MysqlEgresoDAO extends EgresoDAO {
|
||||
|
||||
public MysqlEgresoDAO(){
|
||||
this.connectionHolder = new MysqlConnectionHolder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Egreso> findAll() {
|
||||
List<Egreso> egresoList = new ArrayList<>();
|
||||
try {
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("select * from egresos");
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
egresoList = this.egresosFromResultSet(rs);
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return egresoList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Egreso> findById(int id) {
|
||||
List<Egreso> egresoList = new ArrayList<>();
|
||||
try {
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("select * from egresos where id = ?");
|
||||
ps.setInt(1,id);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
egresoList = this.egresosFromResultSet(rs);
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return egresoList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Egreso> findByCaja(Caja caja) {
|
||||
List<Egreso> egresoList = new ArrayList<>();
|
||||
try {
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("select * from egresos where caja_id = ?");
|
||||
ps.setInt(1, caja.getId());
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
egresoList = this.egresosFromResultSet(rs);
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return egresoList;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<Egreso> findByNro(String nro) {
|
||||
List<Egreso> egresoList = new ArrayList<>();
|
||||
try {
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("select * from egresos where nro = ?");
|
||||
ps.setString(1, nro);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
egresoList = this.egresosFromResultSet(rs);
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return egresoList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Egreso> findByTipoEgreso(TipoEgreso tipoEgreso) {
|
||||
List<Egreso> egresoList = new ArrayList<>();
|
||||
try {
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("select * from egresos where tipo_egreso_id = ?");
|
||||
ps.setInt(1, tipoEgreso.getId());
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
egresoList = this.egresosFromResultSet(rs);
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return egresoList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean insertEgreso(Egreso egreso) {
|
||||
int updates;
|
||||
try {
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("insert into egresos (nro, descripcion, valor, tipo_egreso_id, caja_id) values (?,?,?,?,?)");
|
||||
ps.setString(1,egreso.getNro());
|
||||
ps.setString(2,egreso.getDescripcion());
|
||||
ps.setInt(3,egreso.getValor());
|
||||
ps.setInt(4,egreso.getTipoEgreso().getId());
|
||||
ps.setInt(5, egreso.getCaja().getId());
|
||||
|
||||
updates = ps.executeUpdate();
|
||||
ps.close();
|
||||
|
||||
ps = conn.prepareStatement("select last_insert_id()");
|
||||
ResultSet rs = ps.executeQuery();
|
||||
rs.next();
|
||||
egreso.setId(rs.getInt(1));
|
||||
|
||||
rs.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return updates > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateEgreso(Egreso egreso) {
|
||||
int updates;
|
||||
try {
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("update egresos set nro = ?, descripcion = ?, valor = ?, tipo_egreso_id = ?, caja_id = ? where id = ? ");
|
||||
ps.setString(1,egreso.getNro());
|
||||
ps.setString(2,egreso.getDescripcion());
|
||||
ps.setInt(3,egreso.getValor());
|
||||
ps.setInt(4,egreso.getTipoEgreso().getId());
|
||||
ps.setInt(5, egreso.getCaja().getId());
|
||||
ps.setInt(6, egreso.getId());
|
||||
|
||||
updates = ps.executeUpdate();
|
||||
|
||||
ps.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return updates > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteEgreso(Egreso egreso) {
|
||||
int updates;
|
||||
try {
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("delete from egresos where id = ? ");
|
||||
ps.setInt(1, egreso.getId());
|
||||
|
||||
updates = ps.executeUpdate();
|
||||
|
||||
ps.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return updates > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTotalEgreso(Caja caja) {
|
||||
int total = 0;
|
||||
try {
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("select sum(valor) from egresos where caja_id = ?");
|
||||
ps.setInt(1, caja.getId());
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
rs.next();
|
||||
total = rs.getInt(1);
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -28,8 +28,8 @@ 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.MysqlCajaDAO;
|
||||
import danielcortes.xyz.models.tipo_ingreso.MysqlTipoIngresoDAO;
|
||||
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;
|
||||
|
||||
@@ -56,11 +56,11 @@ public abstract class IngresoDAO {
|
||||
ArrayList<Ingreso> ingresosList = new ArrayList<>();
|
||||
while(rs.next()){
|
||||
int tipoIngresoId = rs.getInt("tipo_ingreso_id");
|
||||
TipoIngresoDAO tipoEgresoDAO = new MysqlTipoIngresoDAO();
|
||||
TipoIngresoDAO tipoEgresoDAO = new SQLiteTipoIngresoDAO();
|
||||
TipoIngreso tipoIngreso = tipoEgresoDAO.findById(tipoIngresoId).get(0);
|
||||
|
||||
int cajaId = rs.getInt("caja_id");
|
||||
CajaDAO cajaDAO = new MysqlCajaDAO();
|
||||
CajaDAO cajaDAO = new SQLiteCajaDAO();
|
||||
Caja caja = cajaDAO.findById(cajaId);
|
||||
|
||||
Ingreso ingreso = new Ingreso();
|
||||
|
||||
@@ -1,218 +0,0 @@
|
||||
/*
|
||||
* 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.MysqlConnectionHolder;
|
||||
import danielcortes.xyz.models.caja.Caja;
|
||||
import danielcortes.xyz.models.caja.CajaDAO;
|
||||
import danielcortes.xyz.models.caja.MysqlCajaDAO;
|
||||
import danielcortes.xyz.models.tipo_ingreso.MysqlTipoIngresoDAO;
|
||||
import danielcortes.xyz.models.tipo_ingreso.TipoIngreso;
|
||||
import danielcortes.xyz.models.tipo_ingreso.TipoIngresoDAO;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MysqlIngresoDAO extends IngresoDAO {
|
||||
|
||||
public MysqlIngresoDAO(){
|
||||
this.connectionHolder = new MysqlConnectionHolder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Ingreso> findAll() {
|
||||
List<Ingreso> ingresosList = new ArrayList<>();
|
||||
try {
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("select * from ingresos");
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
ingresosList = this.ingresosFromResultSet(rs);
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return ingresosList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Ingreso> findByCaja(Caja caja) {
|
||||
List<Ingreso> ingresosList = new ArrayList<>();
|
||||
try {
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("select * from ingresos where caja_id = ?");
|
||||
ps.setInt(1, caja.getId());
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
ingresosList = this.ingresosFromResultSet(rs);
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return ingresosList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Ingreso> findById(int id) {
|
||||
List<Ingreso> ingresosList = new ArrayList<>();
|
||||
try {
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("select * from ingresos where id = ?");
|
||||
ps.setInt(1, id);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
ingresosList = this.ingresosFromResultSet(rs);
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return ingresosList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Ingreso> findByTipoIngreso(TipoIngreso tipoIngreso) {
|
||||
List<Ingreso> ingresosList = new ArrayList<>();
|
||||
try {
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("select ingresos.* from ingresos inner join tipos_ingreso on (ingresos.tipo_ingreso_id = tipos_ingreso.id) where ingresos.tipo_ingreso_id = ?");
|
||||
ps.setInt(1, tipoIngreso.getId());
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
ingresosList = this.ingresosFromResultSet(rs);
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return ingresosList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean insertIngreso(Ingreso ingreso) {
|
||||
int updates;
|
||||
try {
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("insert into ingresos (valor, nro_inicial, nro_final, tipo_ingreso_id, caja_id) values (?,?,?,?,?)");
|
||||
ps.setInt(1, ingreso.getValor());
|
||||
ps.setString(2, ingreso.getNroInicial());
|
||||
ps.setString(3, ingreso.getNroFinal());
|
||||
ps.setInt(4, ingreso.getTipoIngreso().getId());
|
||||
ps.setInt(5, ingreso.getCaja().getId());
|
||||
|
||||
updates = ps.executeUpdate();
|
||||
ps.close();
|
||||
|
||||
ps = conn.prepareStatement("select last_insert_id()");
|
||||
ResultSet rs = ps.executeQuery();
|
||||
rs.next();
|
||||
ingreso.setId(rs.getInt(1));
|
||||
|
||||
rs.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return updates > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateIngreso(Ingreso ingreso) {
|
||||
int updates;
|
||||
try {
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("update ingresos set valor = ? , nro_inicial = ?, nro_final = ?, tipo_ingreso_id = ?, caja_id = ? where id = ?");
|
||||
ps.setInt(1,ingreso.getValor());
|
||||
ps.setString(2, ingreso.getNroInicial());
|
||||
ps.setString(3, ingreso.getNroFinal());
|
||||
ps.setInt(4, ingreso.getTipoIngreso().getId());
|
||||
ps.setInt(5, ingreso.getCaja().getId());
|
||||
ps.setInt(6, ingreso.getId());
|
||||
|
||||
updates = ps.executeUpdate();
|
||||
|
||||
ps.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return updates > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteIngreso(Ingreso ingreso) {
|
||||
int updates;
|
||||
try {
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("delete from ingresos where id = ?");
|
||||
ps.setInt(1,ingreso.getId());
|
||||
updates = ps.executeUpdate();
|
||||
ps.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return updates > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTotalIngreso(Caja caja) {
|
||||
int total = 0;
|
||||
try {
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("select sum(valor) from ingresos where caja_id = ?");
|
||||
ps.setInt(1, caja.getId());
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
rs.next();
|
||||
total = rs.getInt(1);
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
/*
|
||||
* 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.tipo_egreso;
|
||||
|
||||
import danielcortes.xyz.data.MysqlConnectionHolder;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MysqlTipoEgresoDAO extends TipoEgresoDAO {
|
||||
|
||||
public MysqlTipoEgresoDAO(){
|
||||
this.connectionHolder = new MysqlConnectionHolder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TipoEgreso> findAll() {
|
||||
List<TipoEgreso> tipoEgresoList = new ArrayList<>();
|
||||
try {
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("select * from tipos_egreso");
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
tipoEgresoList = this.tipoEgresoFromResultSet(rs);
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return tipoEgresoList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TipoEgreso> findById(int id) {
|
||||
List<TipoEgreso> tipoEgresoList = new ArrayList<>();
|
||||
try {
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("select * from tipos_egreso where id = ?");
|
||||
ps.setInt(1, id);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
tipoEgresoList = this.tipoEgresoFromResultSet(rs);
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return tipoEgresoList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TipoEgreso> findByNombre(String nombre) {
|
||||
List<TipoEgreso> tipoEgresoList = new ArrayList<>();
|
||||
try {
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("select * from tipos_egreso where nombre = ?");
|
||||
ps.setString(1, nombre);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
tipoEgresoList = this.tipoEgresoFromResultSet(rs);
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return tipoEgresoList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean insertTipoEgreso(TipoEgreso tipoEgreso) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateTipoEgreso(TipoEgreso tipoEgreso) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteTipoEgreso(TipoEgreso tipoEgreso) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,114 +0,0 @@
|
||||
/*
|
||||
* 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.tipo_ingreso;
|
||||
|
||||
import danielcortes.xyz.data.MysqlConnectionHolder;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MysqlTipoIngresoDAO extends TipoIngresoDAO {
|
||||
public MysqlTipoIngresoDAO(){
|
||||
this.connectionHolder = new MysqlConnectionHolder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TipoIngreso> findAll() {
|
||||
List<TipoIngreso> tiposIngresoList = new ArrayList<>();
|
||||
try {
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("select * from tipos_ingreso");
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
tiposIngresoList = this.tiposIngresoFromResultSet(rs);
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return tiposIngresoList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TipoIngreso> findById(int id) {
|
||||
List<TipoIngreso> tiposIngresoList = new ArrayList<>();
|
||||
try {
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("select * from tipos_ingreso where id = ?");
|
||||
ps.setInt(1,id);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
tiposIngresoList = this.tiposIngresoFromResultSet(rs);
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return tiposIngresoList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TipoIngreso> findByNombre(String nombre) {
|
||||
List<TipoIngreso> tiposIngresoList = new ArrayList<>();
|
||||
try {
|
||||
Connection conn = connectionHolder.getConnection();
|
||||
PreparedStatement ps = conn.prepareStatement("select * from tipos_ingreso where nombre = ?");
|
||||
ps.setString(1,nombre);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
tiposIngresoList = this.tiposIngresoFromResultSet(rs);
|
||||
|
||||
rs.close();
|
||||
ps.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return tiposIngresoList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean insertTipoIngreso(TipoIngreso tipoEgreso) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateTipoIngreso(TipoIngreso tipoEgreso) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteTipoIngreso(TipoIngreso tipoEgreso) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user