Package org.nutz.trans

Examples of org.nutz.trans.Atom


  public TransactionInterceptor(int level) {
    this.level = level;
  }

  public void filter(final InterceptorChain chain) {
    Trans.exec(level, new Atom() {
      public void run() {
        try {
          chain.doChain();
        }
        catch (Throwable e) {
View Full Code Here


    final Context context = Lang.context("{num:0}");
    context.set("z", z);

    System.out.println("\n" + Strings.dup('=', 100));

    Stopwatch sw = Stopwatch.run(new Atom() {
      public void run() {
        int num = 0;
        for (int i = 0; i < max; i++)
          num = num + (i - 1 + 2 - 3 + 4 - 5 + 6 - 7) - z.abc(i);
        System.out.println("Num: " + num);
      }
    });

    System.out.println("\n" + Strings.dup('=', 100));
   
    Stopwatch sw3 = Stopwatch.run(new Atom() {
      public void run() {
        try {
          context.set("num", 0);
          for (int i = 0; i < max; i++)
            context.set("num", El.eval(context.set("i", i), elstr));
          System.out.println("Num: " + context.getInt("num"));
        }
        catch (Exception e) {
          throw Lang.wrapThrow(e);
        }
      }
    });
    System.out.println("\n" + Strings.dup('=', 100));
   
    Stopwatch sw4 = Stopwatch.run(new Atom() {
      public void run() {
        try {
          El el2pre = new El(elstr);
          context.set("num", 0);
          context.set("z", z);
          for (int i = 0; i < max; i++)
            context.set("num", el2pre.eval(context.set("i", i)));
          System.out.println("Num: " + context.getInt("num"));
        }
        catch (Exception e) {
          throw Lang.wrapThrow(e);
        }
      }
    });
    System.out.println("\n" + Strings.dup('=', 100));
   
    Stopwatch sw5 = Stopwatch.run(new Atom() {
      public void run() {
        try {
          El el2pre = new El(elstr);
          context.set("num", 0);
          context.set("z", z);
View Full Code Here

  @Test
  public void test_insert_by_filter() {
    // insert one pet
    final Pet p = pet("xh").setNickName("XiaoHei");
    FieldFilter.create(Pet.class, "id|name").run(new Atom() {
      public void run() {
        dao.insert(p);
      }
    });
    Pet p2 = dao.fetch(Pet.class, p.getId());
View Full Code Here

  @Test
  public void test_update_by_filter() {
    final Pet p = dao.fetch(Pet.class, "xb");
    p.setNickName("XiaoBai");
    FieldFilter.create(Pet.class, "id|name").run(new Atom() {
      public void run() {
        dao.update(p);
      }
    });
    Pet p2 = dao.fetch(Pet.class, p.getId());
View Full Code Here

  @Test
  public void test_select_by_filter() {
    dao.update(dao.fetch(Pet.class, "xb").setNickName("XiaoBai"));
    assertEquals("XiaoBai", dao.fetch(Pet.class, "xb").getNickName());
    final Pet[] pets = new Pet[1];
    FieldFilter.create(Pet.class, "id|name").run(new Atom() {
      public void run() {
        pets[0] = dao.fetch(Pet.class, "xb");
      }
    });
    assertNull(pets[0].getNickName());
View Full Code Here

  @Test
  public void test_query_by_filter() {
    dao.update(dao.fetch(Pet.class, "xb").setNickName("XiaoBai"));
    assertEquals("XiaoBai", dao.fetch(Pet.class, "xb").getNickName());
    final List<Pet> pets = new ArrayList<Pet>();
    FieldFilter.create(Pet.class, "id|name").run(new Atom() {
      public void run() {
        pets.add(dao.query(Pet.class, null, null).get(0));
      }
    });
    assertNull(pets.get(0).getNickName());
View Full Code Here

  public void test_filter_no_field_match() {
    dao.create(EmtryObject.class, true);
    final EmtryObject obj = new EmtryObject();

    // 应该抛出一个DaoException,因为没有任何的字段需要插入!
    FieldFilter.create(EmtryObject.class, "id").run(new Atom() {
      public void run() {
        dao.insert(obj);
      }
    });
View Full Code Here

    });
  }

  @Test
  public void delete_null_field_links() {
    TableName.run(platoon, new Atom() {
      public void run() {
        Platoon p = dao.fetchLinks(dao.fetch(Platoon.class), "tanks|soliders");
        dao.deleteLinks(p, "tanks|soliders");
        assertEquals(1, dao.count(Platoon.class));
        assertEquals(0, dao.count(Soldier.class));
View Full Code Here

    });
  }

  @Test
  public void delete_links_partly() {
    TableName.run(platoon, new Atom() {
      public void run() {
        TableName.run(platoon, new Atom() {
          public void run() {
            Soldier s = dao.fetchLinks(dao.fetch(Soldier.class, "ZZH"), "guns");
            s.getGuns()[1] = null;
            dao.deleteLinks(s, "guns");
            assertEquals(9, dao.count(Gun.class));
View Full Code Here

    });
  }

  @Test
  public void delete_null_field_links_partly() {
    TableName.run(platoon, new Atom() {
      public void run() {
        Platoon p = dao.fetchLinks(dao.fetch(Platoon.class), "tanks|soliders");
        p.getTanks().remove("M1-A1");
        p.getSoliders().remove(0);
        dao.deleteLinks(p, "tanks|soliders");
View Full Code Here

TOP

Related Classes of org.nutz.trans.Atom

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.