Git Repository Public Repository

RRRRHHHH_Code

URLs

Copy to Clipboard

Diff Revisions 1d7e49 ... vs d30bcc ... for ruralHouses/src/dataAccess/DB4oManager.java

Diff revisions: vs.
  @@ -81,19 +81,11 @@
81 81 configuration = Db4oEmbedded.newConfiguration();
82 82 configuration.common().activationDepth(c.getActivationDepth());
83 83 configuration.common().updateDepth(c.getUpdateDepth());
84 - configuration.common().objectClass(Owner.class).cascadeOnDelete(true);
85 - configuration.common().objectClass(Booking.class).cascadeOnDelete(true);
86 - configuration.common().objectClass(RuralHouse.class)
87 - .cascadeOnDelete(true);
88 - configuration.common().objectClass(Account.class).cascadeOnDelete(true);
89 - configuration.common().objectClass(Offer.class).cascadeOnDelete(true);
90 84 configuration.common().objectClass(Owner.class).cascadeOnUpdate(true);
91 - configuration.common().objectClass(Booking.class).cascadeOnUpdate(true);
85 + configuration.common().objectClass(Owner.class).cascadeOnDelete(true);
92 86 configuration.common().objectClass(RuralHouse.class)
93 87 .cascadeOnUpdate(true);
94 88 configuration.common().objectClass(Account.class).cascadeOnUpdate(true);
95 - configuration.common().objectClass(Offer.class).cascadeOnUpdate(true);
96 - configuration.common().objectClass(Account.class).cascadeOnUpdate(true);
97 89 db = Db4oEmbedded.openFile(configuration, c.getDb4oFilename());
98 90 }
99 91
  @@ -215,7 +207,7 @@
215 207 try {
216 208 ObjectSet<Offer> of = db.queryByExample(offer);
217 209 RuralHouse rh = of.get(0).getRuralHouse();
218 - System.out.println(rh.getAllOffers().remove(of.get(0)));
210 + System.out.println(rh.offers.remove(of.get(0)));
219 211 db.store(rh);
220 212 db.commit();
221 213
  @@ -227,15 +219,14 @@
227 219 }
228 220 }
229 221
230 - public Vector<Offer> getRHsOffer(String name) {
222 + public Vector<Offer> getRHsOffer(String name){
231 223 if (c.isDatabaseLocal() == false)
232 224 openSDB();
233 225 else
234 226 openDB();
235 227
236 228 try {
237 - RuralHouse rh = (RuralHouse) db.queryByExample(
238 - new RuralHouse(name, null, null, null, null)).get(0);
229 + RuralHouse rh = (RuralHouse)db.queryByExample(new RuralHouse(name, null, null, null, null)).get(0);
239 230 Offer proto = new Offer(0, rh, null, null, 0);
240 231 ObjectSet<Offer> result = db.queryByExample(proto);
241 232 return new Vector<Offer>(result);
  @@ -243,8 +234,8 @@
243 234 db.close();
244 235 }
245 236 }
246 -
247 - public Administrator getAdminData() {
237 +
238 + public Administrator getAdminData(){
248 239
249 240 if (c.isDatabaseLocal() == false)
250 241 openSDB();
  @@ -328,12 +319,12 @@
328 319 openSDB();
329 320
330 321 RuralHouse proto = new RuralHouse(ruralHouse.getHouseName(), null,
331 - ruralHouse.getDescription(), ruralHouse.getDistrict(), null);
322 + null, null, null);
332 323 ObjectSet<RuralHouse> result = db.queryByExample(proto);
333 324 RuralHouse rh = (RuralHouse) result.next();
334 325
335 326 Offer offer;
336 - offer = rh.findOffer(firstDate, lastDate);
327 + offer = (Offer)db.queryByExample(new Offer(0, rh, firstDate, lastDate, 0)).get(0);
337 328
338 329 if (offer != null) {
339 330 offer.createBooking(theDB4oManagerAux.bookingNumber++, cl);
  @@ -380,23 +371,6 @@
380 371 }
381 372 }
382 373
383 - public Vector<RuralHouse> getAllRuralHouses() throws RemoteException,
384 - Exception {
385 -
386 - if (c.isDatabaseLocal() == false)
387 - openSDB();
388 - else
389 - openDB();
390 -
391 - try {
392 - RuralHouse proto = new RuralHouse(null, null, null, null, null);
393 - ObjectSet<RuralHouse> result = db.queryByExample(proto);
394 - return new Vector<RuralHouse>(result);
395 - } finally {
396 - db.close();
397 - }
398 - }
399 -
400 374 public boolean existsOverlappingOffer(RuralHouse rh, Date firstDay,
401 375 Date lastDay) throws RemoteException, OverlappingOfferExists {
402 376
  @@ -419,10 +393,6 @@
419 393 }
420 394 }
421 395
422 - public static ObjectContainer getContainer() {
423 - return db;
424 - }
425 -
426 396 public void close() {
427 397 db.close();
428 398 System.out.println("DataBase closed");
  @@ -516,8 +486,8 @@
516 486
517 487 }
518 488
519 - public Vector<RuralHouse> getRuralHouses(Owner ow, String name,
520 - String town, int nBed, int nKit, int nBath, int nPark, int nLiv) {
489 + public Vector<RuralHouse> getRuralHouses(Owner ow, String name, String town,
490 + int nBed, int nKit, int nBath, int nPark, int nLiv) {
521 491 HouseFeatures fea = new HouseFeatures(nBed, nKit, nBath, nLiv, nPark);
522 492 RuralHouse rh = new RuralHouse(name, ow, null, town, fea);
523 493 if (c.isDatabaseLocal() == false)
  @@ -560,16 +530,20 @@
560 530 return false;
561 531 }
562 532
563 - public boolean removeAccount(Owner own) {
533 + // TODO remove account
534 +
535 + public boolean removeAccount(Account acc) {
564 536 if (c.isDatabaseLocal() == false)
565 537 openSDB();
566 538 else
567 539 openDB();
568 540
569 541 try {
570 - ObjectSet<Account> result = db.queryByExample(new Account(own));
542 + ObjectSet<Account> result = db.queryByExample(new Account(acc
543 + .getUsername()));
571 544 if (!result.isEmpty()) {
572 545 db.delete(result.get(0));
546 + ;
573 547 db.commit();
574 548 return true;
575 549 }
  @@ -581,10 +555,10 @@
581 555 return false;
582 556 }
583 557
558 + // TODO this method should be improved.
584 559 public void acceptBooking(Offer of) {
585 - Offer off = new Offer(of.getOfferNumber(), new RuralHouse(of
586 - .getRuralHouse().getHouseName(), null, null, null, null), null,
587 - null, 0);
560 + Offer off = new Offer(of.getOfferNumber(), of.getRuralHouse(),
561 + of.getFirstDay(), of.getLastDay(), of.getPrice());
588 562 if (c.isDatabaseLocal() == false)
589 563 openSDB();
590 564 else
  @@ -592,12 +566,8 @@
592 566
593 567 try {
594 568 ObjectSet<Offer> result = db.queryByExample(off);
595 - db.delete(result.get(0));
596 - RuralHouse rh = result.get(0).getRuralHouse();
597 - of.setRuralHouse(rh);
598 - rh.getAllOffers().remove(result.get(0));
599 - rh.getAllOffers().add(of);
600 - db.store(rh);
569 + this.deleteOffer(result.get(0));
570 + db.store(of);
601 571 db.close();
602 572
603 573 } catch (Exception e) {
  @@ -612,15 +582,14 @@
612 582 else
613 583 openDB();
614 584 try {
615 - Booking book = new Booking(b.getBookNumber(), new Offer(b
616 - .getOffer().getOfferNumber(), new RuralHouse(b.getOffer()
617 - .getRuralHouse().getHouseName(), null, null, null, null),
618 - null, null, 0), b.getClient(), b.getBookDate());
619 - book.setOffer(null);
620 - db.delete(book);
585 + ObjectSet<Booking> result = db.queryByExample(b);
586 + ObjectSet<Client> result2 = db.queryByExample(b.getClient());
587 + db.delete(result.get(0));
588 + db.delete(result2.get(0));
621 589 db.commit();
622 590 } catch (Exception e) {
623 591 e.printStackTrace();
592 + ;
624 593 } finally {
625 594 db.close();
626 595 }