/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Metier;
import Physique.ArmoireServiceJDBC;
import Physique.EtagereServiceJDBC;
import Physique.StructureBibliothequeServiceJDBC;
import java.util.ArrayList;
public class ArmoireServiceImpl implements ArmoireService {
ArmoireServiceJDBC armoireJDBC = Physique.PhysiqueFactory.getArmoireService();
StructureBibliothequeServiceJDBC sbs = Physique.PhysiqueFactory.getStructureService();
EtagereServiceJDBC es = Physique.PhysiqueFactory.getEtagereService();
protected ArmoireServiceImpl() {
}
@Override
public void add(Armoire armoire) {
if (armoire != null) {
armoireJDBC.add(armoire);
}
}
@Override
public void update(Armoire armoire) {
if (armoire != null) {
armoireJDBC.update(armoire);
}
}
@Override
public void remove(Armoire armoire) {
if (armoire != null) {
ArrayList<StructureBibliotheque> all = sbs.getAll();
for (int i = 0; i < all.size(); i++) {
StructureBibliotheque sb = all.get(i);
if (sb.getArmoires() != null) {
for (int y = 0; y < sb.getArmoires().size(); y++) {
Armoire armoireEnCours = sb.getArmoires().get(y);
if (armoireEnCours.getCharArmoire().equals(armoire.getCharArmoire())) {
if (armoireEnCours.getId() == armoire.getId()) {
sb.getArmoires().remove(armoireEnCours);
sbs.update(sb);
}
}
}
}
}
for (int i = 0; i < armoire.getEtageres().size(); i++) {
es.remove(armoire.getEtageres().get(i));
}
armoireJDBC.remove(armoire);
}
}
@Override
public ArrayList<Armoire> getAll() {
return armoireJDBC.getAll();
}
@Override
public Armoire getById(int id) {
if (id != 0) {
return armoireJDBC.getById(id);
}
return null;
}
}