Esempio n. 1
0
  private void findAndRateBeer(User user) {
    System.out.print("beer to find: ");
    String n = scanner.nextLine();
    Beer foundBeer = server.find(Beer.class).where().like("name", n).findUnique();

    if (foundBeer == null) {
      System.out.println(n + " not found");
      return;
    }
    int quantity = 0;
    int ratingsCombined = 0;
    int average = 0;
    List<Rating> ratings = server.find(Rating.class).where().findList();
    for (Rating rating : ratings) {
      if (rating.getBeer().getName().equals(n)) {
        ratingsCombined += rating.getRating();
        quantity++;
      }
    }
    if (quantity > 0) {
      average = ratingsCombined / quantity;
    }

    System.out.println("found: " + foundBeer);
    System.out.println("  number of ratings: " + quantity + " average " + average);
    System.out.print("give rating (leave empty if not): ");
    int ratingValue = scanner.nextInt();

    Rating rating = new Rating(user, foundBeer, ratingValue);
    server.save(rating);
  }
Esempio n. 2
0
  @Test
  public void testBasicOperations() {

    Account e = buildAccount(-1);

    // Get the default EbeanServer and save
    EbeanServer server = Ebean.getServer(null);
    server.save(e);
    Assert.assertNotNull(e.getId());

    e.setEmail("banana");
    server.update(e);

    // find by id
    Account e2 = server.find(Account.class, e.getId());
    Assert.assertNotNull("we found it in the db", e2);
    Assert.assertTrue("different instance", e2 != e);
    Assert.assertEquals("updated description", "banana", e2.getEmail());

    server.delete(e2);

    Account e3 = server.find(Account.class, e.getId());
    Assert.assertNull("its been deleted", e3);

    Query<Card> query = Ebean.find(Card.class);
  }
Esempio n. 3
0
 void addSign(TeleportSign ts) {
   signs.add(ts);
   database.save(ts);
   if (debugmode)
     Bukkit.getLogger()
         .log(
             Level.INFO, "[TeleportSigns] Saved TeleportSign at {0}", ts.getLocation().toString());
 }
Esempio n. 4
0
  private void createNewUser() {
    System.out.print("give username: "******"user created");
  }
Esempio n. 5
0
  // jos kanta on luotu uudelleen, suoritetaan tämä ja laitetaan kantaan hiukan dataa
  private void seedDatabase() throws OptimisticLockException {
    Brewery brewery = new Brewery("Schlenkerla");
    brewery.addBeer(new Beer("Urbock"));
    brewery.addBeer(new Beer("Lager"));
    // tallettaa myös luodut oluet, sillä Brewery:n OneToMany-mappingiin on määritelty
    // CascadeType.all
    server.save(brewery);

    // luodaan olut ilman panimon asettamista
    Beer b = new Beer("Märzen");
    server.save(b);

    // jotta saamme panimon asetettua, tulee olot lukea uudelleen kannasta
    b = server.find(Beer.class, b.getId());
    brewery = server.find(Brewery.class, brewery.getId());
    brewery.addBeer(b);
    server.save(brewery);
    server.save(new Pub("Pikkulintu"));
    server.save(new Brewery("Paulaner"));
  }
 /** {@inheritDoc} */
 @Override
 @Transactional
 public Session create(String name, String description, String estimations) {
   Session session = new Session();
   session.setName(name);
   session.setDescription(description);
   session.setEstimates(estimations);
   session.setCode(newCode(SESSION_CODE_LENGTH.asInt().or(SESSION_CODE_DEFAULT_LENGTH)));
   session.setAuthor(userService.getCurrentUser());
   ebean.save(session);
   return session;
 }
Esempio n. 7
0
  private void addPub() {
    System.out.print("pub to add: ");

    String name = scanner.nextLine();

    Pub exists = server.find(Pub.class).where().like("name", name).findUnique();
    if (exists != null) {
      System.out.println(name + " exists already");
      return;
    }

    server.save(new Pub(name));
  }
Esempio n. 8
0
  private void addBrewery() {
    System.out.println("brewery name: ");
    String name = scanner.nextLine();

    Brewery brewery = server.find(Brewery.class).where().like("name", name).findUnique();

    if (brewery != null) {
      System.out.println(name + " already exists");
    } else {
      brewery = new Brewery(name);
      server.save(brewery);
      System.out.println("new brewery: " + name + " created");
    }
  }
Esempio n. 9
0
  @Test
  public void testBatch() {
    int rowsNumber = 100;

    EbeanServer server = Ebean.getServer(null);
    Transaction transaction = server.beginTransaction();
    transaction.setBatchMode(true);
    transaction.setBatchSize(30);
    try {
      for (int i = 0; i < rowsNumber; i++) {
        server.save(buildAccount(i));
      }
      server.commitTransaction();
    } finally {
      server.endTransaction();
    }
    List<Account> all = server.find(Account.class).select("name").findList();
    Assert.assertEquals("Batch update", rowsNumber, all.size());
  }
Esempio n. 10
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);
  }
Esempio n. 11
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);
  }
Esempio n. 12
0
  private void addBeer() {
    System.out.print("to which brewery: ");
    String name = scanner.nextLine();
    Brewery brewery = server.find(Brewery.class).where().like("name", name).findUnique();

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

    System.out.print("beer to add: ");

    name = scanner.nextLine();

    Beer exists = server.find(Beer.class).where().like("name", name).findUnique();
    if (exists != null) {
      System.out.println(name + " exists already");
      return;
    }

    brewery.addBeer(new Beer(name));
    server.save(brewery);
    System.out.println(name + " added to " + brewery.getName());
  }
Esempio n. 13
0
 public static void create(Official official, ProcessingType processingType) {
   if (processingType.equals(ProcessingType.batch)) ebeanServer.save(official);
   else if (processingType.equals(ProcessingType.online)) Ebean.save(official);
 }
Esempio n. 14
0
 @Override
 public void saveHomeInvite(HomeInvite homeInvite) {
   Transaction tx = ebean.beginTransaction();
   ebean.save(homeInvite, tx);
   tx.commit();
 }