示例#1
0
  private void listPubsAndBeers() {
    List<Pub> pubs = server.find(Pub.class).findList();

    for (Pub pub : pubs) {
      System.out.println(pub.getName());
      for (Beer beer : pub.getBeers()) {
        System.out.println("  -" + beer.getName());
      }
    }
  }
示例#2
0
  private void showBeers() {
    System.out.print("which pub: ");
    String pub = scanner.nextLine();

    Pub foundPub = server.find(Pub.class).where().like("name", pub).findUnique();
    if (foundPub == null) {
      System.out.println("pub doesn't exist");
      return;
    }
    List<Beer> beers = foundPub.getBeers();
    for (Beer beer : beers) {
      System.out.println(beer.getName());
    }
  }
示例#3
0
  private void removeBeerFromPub() {
    System.out.print("which pub: ");
    String pub = scanner.nextLine();
    Pub foundPub = server.find(Pub.class).where().like("name", pub).findUnique();
    if (foundPub == null) {
      System.out.println("pub doesn't exist");
      return;
    }

    System.out.print("which beer:");
    String beer = scanner.nextLine();
    Beer foundBeer = server.find(Beer.class).where().like("name", beer).findUnique();
    if (foundBeer == null) {
      System.out.println("Beer doesn't exist");
      return;
    }
    foundPub.removeBeer(foundBeer);
    server.save(foundPub);
  }
示例#4
0
  private void addBeerToPub() {
    System.out.print("beer: ");
    String name = scanner.nextLine();
    Beer beer = server.find(Beer.class).where().like("name", name).findUnique();

    if (beer == null) {
      System.out.println("does not exist");
      return;
    }

    System.out.print("pub: ");
    name = scanner.nextLine();
    Pub pub = server.find(Pub.class).where().like("name", name).findUnique();

    if (pub == null) {
      System.out.println("does not exist");
      return;
    }

    pub.addBeer(beer);
    server.save(pub);
  }