|
@@ -135,7 +135,6 @@ |
135 |
135 |
|
Account alfredoAcc = new Account("userAlfredo", "passAlfredo", |
136 |
136 |
|
alfredo); |
137 |
137 |
|
|
138 |
|
- |
|
139 |
138 |
|
Account admin = new Account("admin", "admin", true); |
140 |
139 |
|
db.store(Administrator.getInstance()); |
141 |
140 |
|
db.store(jonAcc); |
|
@@ -237,6 +236,7 @@ |
237 |
236 |
|
} |
238 |
237 |
|
|
239 |
238 |
|
public Administrator getAdminData(){ |
|
239 |
+ |
|
240 |
240 |
|
if (c.isDatabaseLocal() == false) |
241 |
241 |
|
openSDB(); |
242 |
242 |
|
else |
|
@@ -244,8 +244,7 @@ |
244 |
244 |
|
|
245 |
245 |
|
try { |
246 |
246 |
|
|
247 |
|
- |
|
248 |
|
- |
List<Administrator> admL = db.query(new Predicate<Administrator>(){ |
|
247 |
+ |
List<Administrator> admL = db.query(new Predicate<Administrator>() { |
249 |
248 |
|
private static final long serialVersionUID = 1L; |
250 |
249 |
|
|
251 |
250 |
|
public boolean match(Administrator admin) { |
|
@@ -253,11 +252,8 @@ |
253 |
252 |
|
} |
254 |
253 |
|
}); |
255 |
254 |
|
|
256 |
|
- |
|
257 |
|
- |
|
258 |
255 |
|
return admL.get(0); |
259 |
|
- |
} |
260 |
|
- |
finally { |
|
256 |
+ |
} finally { |
261 |
257 |
|
db.close(); |
262 |
258 |
|
|
263 |
259 |
|
} |
|
@@ -315,7 +311,7 @@ |
315 |
311 |
|
else |
316 |
312 |
|
openDB(); |
317 |
313 |
|
|
318 |
|
- |
Vector<Booking> book = new Vector<Booking>() ; |
|
314 |
+ |
Vector<Booking> book = new Vector<Booking>(); |
319 |
315 |
|
|
320 |
316 |
|
try { |
321 |
317 |
|
|
|
@@ -334,11 +330,11 @@ |
334 |
330 |
|
offer.createBooking(theDB4oManagerAux.bookingNumber++, cl); |
335 |
331 |
|
db.store(theDB4oManagerAux); // To store the new value for |
336 |
332 |
|
// bookingNumber |
337 |
|
- |
|
|
333 |
+ |
|
338 |
334 |
|
db.store(offer); |
339 |
335 |
|
db.commit(); |
340 |
336 |
|
book = offer.getBookings(); |
341 |
|
- |
|
|
337 |
+ |
|
342 |
338 |
|
} |
343 |
339 |
|
|
344 |
340 |
|
} catch (com.db4o.ext.ObjectNotStorableException e) { |
|
@@ -541,27 +537,50 @@ |
541 |
537 |
|
openDB(); |
542 |
538 |
|
|
543 |
539 |
|
try { |
544 |
|
- |
// TODO realize if there is another account with same username. |
545 |
|
- |
// Quite difficult with the f***ing salt |
546 |
|
- |
db.store(acc); |
547 |
|
- |
db.commit(); |
|
540 |
+ |
ObjectSet<Account> result = db.queryByExample(new Account(acc |
|
541 |
+ |
.getUsername())); |
|
542 |
+ |
if (result.isEmpty()) { |
|
543 |
+ |
db.store(acc); |
|
544 |
+ |
db.commit(); |
|
545 |
+ |
return true; |
|
546 |
+ |
} |
548 |
547 |
|
} catch (Exception exc) { |
549 |
548 |
|
exc.printStackTrace(); |
550 |
549 |
|
} finally { |
551 |
550 |
|
db.close(); |
552 |
551 |
|
} |
553 |
|
- |
return true; |
|
552 |
+ |
return false; |
554 |
553 |
|
} |
555 |
554 |
|
|
556 |
555 |
|
// TODO remove account |
557 |
556 |
|
|
558 |
557 |
|
public boolean removeAccount(Account acc) { |
|
558 |
+ |
if (c.isDatabaseLocal() == false) |
|
559 |
+ |
openSDB(); |
|
560 |
+ |
else |
|
561 |
+ |
openDB(); |
|
562 |
+ |
|
|
563 |
+ |
try { |
|
564 |
+ |
ObjectSet<Account> result = db.queryByExample(new Account(acc |
|
565 |
+ |
.getUsername())); |
|
566 |
+ |
if (!result.isEmpty()) { |
|
567 |
+ |
db.delete(result.get(0)); |
|
568 |
+ |
; |
|
569 |
+ |
db.commit(); |
|
570 |
+ |
return true; |
|
571 |
+ |
} |
|
572 |
+ |
} catch (Exception exc) { |
|
573 |
+ |
exc.printStackTrace(); |
|
574 |
+ |
} finally { |
|
575 |
+ |
db.close(); |
|
576 |
+ |
} |
559 |
577 |
|
return false; |
560 |
578 |
|
} |
561 |
|
- |
|
562 |
|
- |
//TODO this method should be improved. |
563 |
|
- |
public void acceptBooking(Offer of){ |
564 |
|
- |
Offer off = new Offer(of.getOfferNumber(),of.getRuralHouse(),of.getFirstDay(),of.getLastDay(),of.getPrice()); |
|
579 |
+ |
|
|
580 |
+ |
// TODO this method should be improved. |
|
581 |
+ |
public void acceptBooking(Offer of) { |
|
582 |
+ |
Offer off = new Offer(of.getOfferNumber(), of.getRuralHouse(), |
|
583 |
+ |
of.getFirstDay(), of.getLastDay(), of.getPrice()); |
565 |
584 |
|
if (c.isDatabaseLocal() == false) |
566 |
585 |
|
openSDB(); |
567 |
586 |
|
else |
|
@@ -572,29 +591,30 @@ |
572 |
591 |
|
this.deleteOffer(result.get(0)); |
573 |
592 |
|
db.store(of); |
574 |
593 |
|
db.close(); |
575 |
|
- |
|
|
594 |
+ |
|
576 |
595 |
|
} catch (Exception e) { |
577 |
|
- |
e.printStackTrace();; |
578 |
|
- |
} |
|
596 |
+ |
e.printStackTrace(); |
|
597 |
+ |
; |
|
598 |
+ |
} |
579 |
599 |
|
} |
580 |
|
- |
|
581 |
|
- |
public void removeBooking(Booking b){ |
|
600 |
+ |
|
|
601 |
+ |
public void removeBooking(Booking b) { |
582 |
602 |
|
if (c.isDatabaseLocal() == false) |
583 |
603 |
|
openSDB(); |
584 |
604 |
|
else |
585 |
605 |
|
openDB(); |
586 |
606 |
|
try { |
587 |
607 |
|
ObjectSet<Booking> result = db.queryByExample(b); |
588 |
|
- |
ObjectSet<Client> result2= db.queryByExample(b.getClient()); |
|
608 |
+ |
ObjectSet<Client> result2 = db.queryByExample(b.getClient()); |
589 |
609 |
|
db.delete(result.get(0)); |
590 |
610 |
|
db.delete(result2.get(0)); |
591 |
611 |
|
db.commit(); |
592 |
612 |
|
} catch (Exception e) { |
593 |
|
- |
e.printStackTrace();; |
594 |
|
- |
}finally{ |
|
613 |
+ |
e.printStackTrace(); |
|
614 |
+ |
; |
|
615 |
+ |
} finally { |
595 |
616 |
|
db.close(); |
596 |
617 |
|
} |
597 |
618 |
|
|
598 |
|
- |
|
599 |
619 |
|
} |
600 |
620 |
|
} |