if (!suitsRegulations(rh.getFeatures().getnKitchens(), rh.getFeatures()
.getnBaths(), rh.getFeatures().getnKitchens()))
return false;
- rh.getOwner().getRuralHouses().add(rh);
stored = this.dbMngr.storeRuralHouses(rh);
return stored;
}
RuralHouse house = new RuralHouse(rh.getHouseName(), null, null, null,
null);
try {
- ObjectSet<Owner> result = db.queryByExample(house);
+ ObjectSet<RuralHouse> result = db.queryByExample(house);
if (result.isEmpty()) {
- db.store(rh);
+ Owner ow = (Owner) db.queryByExample(rh.getOwner()).get(0);
+ db.delete(ow);
+ ow.addRuralHouse(rh);
+ db.store(ow);
db.commit();
stored = true;
} else {
if (!rhs.isEmpty()) {
Owner found = result.get(0);
found.getRuralHouses().remove(rhs.get(0));
+ db.delete(rhs.get(0));
db.store(found);
db.commit();
}
ruralHouses.add(rh);
return rh;
}
+
+ public RuralHouse addRuralHouse(RuralHouse rh) {
+ ruralHouses.add(rh);
+ return rh;
+ }
public String toString() {
return name;
JButton btnNewButton = new JButton("Confirm Addition");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
- if (table.getRowCount()!=0) {
+ if (table.getRowCount()!=0 && table.getSelectedRow() != -1) {
HouseManagerInterface hm = new HouseManager();
RuralHouse rh = houses.get(table.getSelectedRow());
//TODO when the house is not added show a warning to the user. Method below returns a boolean stating that.