Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aplicación del Patron Creacional: Builder Method #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions src/Logica/MunicipioBuilder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
public class MunicipioBuilder {
private dMunicipios municipio = new dMunicipios();

public MunicipioBuilder setId(String id) {
municipio.setId_municipio(id);
return this;
}

public MunicipioBuilder setNombre(String nombre) {
municipio.setNombre_municipio(nombre);
return this;
}

public MunicipioBuilder setUbicacion(String ubicacion) {
municipio.setUbicacion_municipio(ubicacion);
return this;
}

public MunicipioBuilder setClima(String clima) {
municipio.setClima_municipio(clima);
return this;
}

public MunicipioBuilder setEscudo(FileInputStream escudo) {
municipio.setEscudo_municipio(escudo);
return this;
}

public MunicipioBuilder setIdRegion(String idRegion) {
municipio.setId_region_municipio(idRegion);
return this;
}

public MunicipioBuilder setNumHabitantes(int numHabitantes) {
municipio.setNumero_habitantes(numHabitantes);
return this;
}

public MunicipioBuilder setNumMujeres(int numMujeres) {
municipio.setNumero_mujeres(numMujeres);
return this;
}

public MunicipioBuilder setNumHombres(int numHombres) {
municipio.setNumero_hombre(numHombres);
return this;
}

public dMunicipios build() {
return municipio;
}
}
17 changes: 17 additions & 0 deletions src/Logica/dMunicipios.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
public class dMunicipios {
private String id_municipio;
private String nombre_municipio;
private String ubicacion_municipio;
private String clima_municipio;
private FileInputStream escudo_municipio;
private String id_region_municipio;
private int numero_habitantes;
private int numero_mujeres;
private int numero_hombre;

// Constructor privado para evitar instancias directas
private dMunicipios() {}

// Getters y setters para los atributos
// ...
}
37 changes: 34 additions & 3 deletions src/Logica/fMunicipios.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,13 @@ public DefaultTableModel mostrarNomMuni(String buscar){


//Metodo Insertar Municipio
public boolean insertar(dMunicipios dts){
/*public boolean insertar(dMunicipios dts){

sSQL = " INSERT INTO municipios (id_municipios, nombre_municipio, ubicacion_municipio,"+
" clima_municipio, escudo_municipio, id_region, numero_habitantes_municipio,"+
" numero_mujeres, numero_hombre) values(?,?,?,?,?,?,?,?,?)";




try {

Expand Down Expand Up @@ -165,7 +166,37 @@ public boolean insertar(dMunicipios dts){

}


*/
public boolean insertarConBuilder(MunicipioBuilder builder) {
try {
dMunicipios municipio = builder.build();
sSQL = "INSERT INTO municipios (id_municipios, nombre_municipio, ubicacion_municipio," +
" clima_municipio, escudo_municipio, id_region, numero_habitantes_municipio," +
" numero_mujeres, numero_hombre) values(?,?,?,?,?,?,?,?,?)";

PreparedStatement pat = cn.prepareStatement(sSQL);
pat.setString(1, municipio.getId_municipio());
pat.setString(2, municipio.getNombre_municipio());
pat.setString(3, municipio.getUbicacion_municipio());
pat.setString(4, municipio.getClima_municipio());
pat.setBinaryStream(5, municipio.getEscudo_municipio());
pat.setString(6, municipio.getId_region_municipio());
pat.setInt(7, municipio.getNumero_habitantes());
pat.setInt(8, municipio.getNumero_mujeres());
pat.setInt(9, municipio.getNumero_hombre());

int n = pat.executeUpdate();

if (n != 0) {
return true;
} else {
return false;
}
} catch (Exception e) {
JOptionPane.showConfirmDialog(null, e);
return false;
}
}


public ArrayList<String> llenar_combo_Municipios(String id){
Expand Down