コード例 #1
0
ファイル: JPAPagingTest.java プロジェクト: rapidoid/rapidoid
  @Test
  public void testPaging() {
    JPA.bootstrap(path());

    int total = 15;

    JPA.transaction(
        () -> {
          for (int i = 0; i < total; i++) {
            Book book = JPA.insert(new Book("b" + i));
            notNull(book.getId());
          }
        });

    JPA.transaction(
        () -> {
          eq(JPA.getAllEntities().size(), total);
          eq(JPA.count(Book.class), total);

          eq(JPA.of(Book.class).all().size(), total);

          List<Book> first3 = JPA.of(Book.class).page(0, 3);
          eq(first3.size(), 3);
          eq(Do.map(first3).to(Book::getTitle), U.list("b0", "b1", "b2"));

          List<Book> next5 = JPA.of(Book.class).page(3, 5);
          eq(Do.map(next5).to(Book::getTitle), U.list("b3", "b4", "b5", "b6", "b7"));

          List<Book> last2 = JPA.of(Book.class).page(13, 2);
          eq(Do.map(last2).to(Book::getTitle), U.list("b13", "b14"));
        });
  }
コード例 #2
0
ファイル: Oneliners.java プロジェクト: Joram550A/rapidoid
  public static void main(String[] args) {

    Map<String, String> cfg = U.map("title", "App", "user", "u1", "theme", "x");

    On.get("/cfg").json(cfg);

    PageMenu menu = PageMenu.from(U.map("Home", "/", "Groups", "/group"));

    On.defaultWrap((data, next) -> next.invoke(x -> page(x).menu(menu).title(cfg.get("title"))));

    List<Btn> letters = Flow.chars('a', 'z').map(c -> btn(c).linkTo("/find?p=" + c)).toList();

    On.page("/")
        .gui("p", p -> U.list(letters, grid(cfg).keyView(k -> a(k).href("/edit?key=" + k))));

    On.page("/group")
        .gui(
            "x",
            x -> {
              return Do.map(Do.group(cfg).by((k, v) -> k.charAt(0)))
                  .toList((k, v) -> U.list(h3(k), grid(v)));
            });

    On.page("/find")
        .gui("p", p -> U.list(letters, grid(Find.allOf(cfg).where((k, v) -> k.startsWith(p)))));

    Btn ok = btn("Update").onClick(() -> Log.info("Updated", "cfg", cfg));

    On.page("/edit").gui("key", key -> edit(cfg, key).buttons(ok, btn("Back").linkTo("/")));

    Runnable replicate = () -> REST.get("http://localhost:8888/cfg", Object.class, U::print);

    Jobs.scheduleAtFixedRate(replicate, 3, 3, TimeUnit.SECONDS);
  }