|
@@ -135,6 +135,7 @@ |
135 |
135 |
|
Account alfredoAcc = new Account("userAlfredo", "passAlfredo", |
136 |
136 |
|
alfredo); |
137 |
137 |
|
|
|
138 |
+ |
|
138 |
139 |
|
Account admin = new Account("admin", "admin", true); |
139 |
140 |
|
db.store(Administrator.getInstance()); |
140 |
141 |
|
db.store(jonAcc); |
|
@@ -219,15 +220,32 @@ |
219 |
220 |
|
} |
220 |
221 |
|
} |
221 |
222 |
|
|
222 |
|
- |
public Administrator getAdminData() { |
|
223 |
+ |
public Vector<Offer> getRHsOffer(String name){ |
223 |
224 |
|
if (c.isDatabaseLocal() == false) |
224 |
225 |
|
openSDB(); |
225 |
226 |
|
else |
226 |
227 |
|
openDB(); |
227 |
228 |
|
|
228 |
229 |
|
try { |
|
230 |
+ |
RuralHouse rh = (RuralHouse)db.queryByExample(new RuralHouse(name, null, null, null, null)).get(0); |
|
231 |
+ |
Offer proto = new Offer(0, rh, null, null, 0); |
|
232 |
+ |
ObjectSet<Offer> result = db.queryByExample(proto); |
|
233 |
+ |
return new Vector<Offer>(result); |
|
234 |
+ |
} finally { |
|
235 |
+ |
db.close(); |
|
236 |
+ |
} |
|
237 |
+ |
} |
|
238 |
+ |
|
|
239 |
+ |
public Administrator getAdminData(){ |
|
240 |
+ |
if (c.isDatabaseLocal() == false) |
|
241 |
+ |
openSDB(); |
|
242 |
+ |
else |
|
243 |
+ |
openDB(); |
229 |
244 |
|
|
230 |
|
- |
List<Administrator> admL = db.query(new Predicate<Administrator>() { |
|
245 |
+ |
try { |
|
246 |
+ |
|
|
247 |
+ |
|
|
248 |
+ |
List<Administrator> admL = db.query(new Predicate<Administrator>(){ |
231 |
249 |
|
private static final long serialVersionUID = 1L; |
232 |
250 |
|
|
233 |
251 |
|
public boolean match(Administrator admin) { |
|
@@ -235,8 +253,11 @@ |
235 |
253 |
|
} |
236 |
254 |
|
}); |
237 |
255 |
|
|
|
256 |
+ |
|
|
257 |
+ |
|
238 |
258 |
|
return admL.get(0); |
239 |
|
- |
} finally { |
|
259 |
+ |
} |
|
260 |
+ |
finally { |
240 |
261 |
|
db.close(); |
241 |
262 |
|
|
242 |
263 |
|
} |
|
@@ -294,7 +315,7 @@ |
294 |
315 |
|
else |
295 |
316 |
|
openDB(); |
296 |
317 |
|
|
297 |
|
- |
Vector<Booking> book = new Vector<Booking>(); |
|
318 |
+ |
Vector<Booking> book = new Vector<Booking>() ; |
298 |
319 |
|
|
299 |
320 |
|
try { |
300 |
321 |
|
|
|
@@ -313,11 +334,11 @@ |
313 |
334 |
|
offer.createBooking(theDB4oManagerAux.bookingNumber++, cl); |
314 |
335 |
|
db.store(theDB4oManagerAux); // To store the new value for |
315 |
336 |
|
// bookingNumber |
316 |
|
- |
|
|
337 |
+ |
|
317 |
338 |
|
db.store(offer); |
318 |
339 |
|
db.commit(); |
319 |
340 |
|
book = offer.getBookings(); |
320 |
|
- |
|
|
341 |
+ |
|
321 |
342 |
|
} |
322 |
343 |
|
|
323 |
344 |
|
} catch (com.db4o.ext.ObjectNotStorableException e) { |
|
@@ -354,6 +375,7 @@ |
354 |
375 |
|
} |
355 |
376 |
|
} |
356 |
377 |
|
|
|
378 |
+ |
|
357 |
379 |
|
public Vector<RuralHouse> getAllRuralHouses() throws RemoteException, |
358 |
380 |
|
Exception { |
359 |
381 |
|
|
|
@@ -365,10 +387,7 @@ |
365 |
387 |
|
try { |
366 |
388 |
|
RuralHouse proto = new RuralHouse(null, null, null, null, null); |
367 |
389 |
|
ObjectSet<RuralHouse> result = db.queryByExample(proto); |
368 |
|
- |
Vector<RuralHouse> ruralHouses = new Vector<RuralHouse>(); |
369 |
|
- |
while (result.hasNext()) |
370 |
|
- |
ruralHouses.add((RuralHouse) result.next()); |
371 |
|
- |
return ruralHouses; |
|
390 |
+ |
return new Vector<RuralHouse>(result); |
372 |
391 |
|
} finally { |
373 |
392 |
|
db.close(); |
374 |
393 |
|
} |
|
@@ -493,10 +512,10 @@ |
493 |
512 |
|
|
494 |
513 |
|
} |
495 |
514 |
|
|
496 |
|
- |
public Vector<RuralHouse> getRuralHouses(String name, String town, |
|
515 |
+ |
public Vector<RuralHouse> getRuralHouses(Owner ow, String name, String town, |
497 |
516 |
|
int nBed, int nKit, int nBath, int nPark, int nLiv) { |
498 |
517 |
|
HouseFeatures fea = new HouseFeatures(nBed, nKit, nBath, nLiv, nPark); |
499 |
|
- |
RuralHouse rh = new RuralHouse(name, null, null, town, fea); |
|
518 |
+ |
RuralHouse rh = new RuralHouse(name, ow, null, town, fea); |
500 |
519 |
|
if (c.isDatabaseLocal() == false) |
501 |
520 |
|
openSDB(); |
502 |
521 |
|
else |
|
@@ -522,50 +541,27 @@ |
522 |
541 |
|
openDB(); |
523 |
542 |
|
|
524 |
543 |
|
try { |
525 |
|
- |
ObjectSet<Account> result = db.queryByExample(new Account(acc |
526 |
|
- |
.getUsername())); |
527 |
|
- |
if (result.isEmpty()) { |
528 |
|
- |
db.store(acc); |
529 |
|
- |
db.commit(); |
530 |
|
- |
return true; |
531 |
|
- |
} |
|
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(); |
532 |
548 |
|
} catch (Exception exc) { |
533 |
549 |
|
exc.printStackTrace(); |
534 |
550 |
|
} finally { |
535 |
551 |
|
db.close(); |
536 |
552 |
|
} |
537 |
|
- |
return false; |
|
553 |
+ |
return true; |
538 |
554 |
|
} |
539 |
555 |
|
|
540 |
556 |
|
// TODO remove account |
541 |
557 |
|
|
542 |
558 |
|
public boolean removeAccount(Account acc) { |
543 |
|
- |
if (c.isDatabaseLocal() == false) |
544 |
|
- |
openSDB(); |
545 |
|
- |
else |
546 |
|
- |
openDB(); |
547 |
|
- |
|
548 |
|
- |
try { |
549 |
|
- |
ObjectSet<Account> result = db.queryByExample(new Account(acc |
550 |
|
- |
.getUsername())); |
551 |
|
- |
if (!result.isEmpty()) { |
552 |
|
- |
db.delete(result.get(0)); |
553 |
|
- |
; |
554 |
|
- |
db.commit(); |
555 |
|
- |
return true; |
556 |
|
- |
} |
557 |
|
- |
} catch (Exception exc) { |
558 |
|
- |
exc.printStackTrace(); |
559 |
|
- |
} finally { |
560 |
|
- |
db.close(); |
561 |
|
- |
} |
562 |
559 |
|
return false; |
563 |
560 |
|
} |
564 |
|
- |
|
565 |
|
- |
// TODO this method should be improved. |
566 |
|
- |
public void acceptBooking(Offer of) { |
567 |
|
- |
Offer off = new Offer(of.getOfferNumber(), of.getRuralHouse(), |
568 |
|
- |
of.getFirstDay(), of.getLastDay(), of.getPrice()); |
|
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()); |
569 |
565 |
|
if (c.isDatabaseLocal() == false) |
570 |
566 |
|
openSDB(); |
571 |
567 |
|
else |
|
@@ -576,30 +572,29 @@ |
576 |
572 |
|
this.deleteOffer(result.get(0)); |
577 |
573 |
|
db.store(of); |
578 |
574 |
|
db.close(); |
579 |
|
- |
|
|
575 |
+ |
|
580 |
576 |
|
} catch (Exception e) { |
581 |
|
- |
e.printStackTrace(); |
582 |
|
- |
; |
583 |
|
- |
} |
|
577 |
+ |
e.printStackTrace();; |
|
578 |
+ |
} |
584 |
579 |
|
} |
585 |
|
- |
|
586 |
|
- |
public void removeBooking(Booking b) { |
|
580 |
+ |
|
|
581 |
+ |
public void removeBooking(Booking b){ |
587 |
582 |
|
if (c.isDatabaseLocal() == false) |
588 |
583 |
|
openSDB(); |
589 |
584 |
|
else |
590 |
585 |
|
openDB(); |
591 |
586 |
|
try { |
592 |
587 |
|
ObjectSet<Booking> result = db.queryByExample(b); |
593 |
|
- |
ObjectSet<Client> result2 = db.queryByExample(b.getClient()); |
|
588 |
+ |
ObjectSet<Client> result2= db.queryByExample(b.getClient()); |
594 |
589 |
|
db.delete(result.get(0)); |
595 |
590 |
|
db.delete(result2.get(0)); |
596 |
591 |
|
db.commit(); |
597 |
592 |
|
} catch (Exception e) { |
598 |
|
- |
e.printStackTrace(); |
599 |
|
- |
; |
600 |
|
- |
} finally { |
|
593 |
+ |
e.printStackTrace();; |
|
594 |
+ |
}finally{ |
601 |
595 |
|
db.close(); |
602 |
596 |
|
} |
603 |
597 |
|
|
|
598 |
+ |
|
604 |
599 |
|
} |
605 |
600 |
|
} |