Package org.nutz.trans

Examples of org.nutz.trans.Atom


        assertTrue(null != dao.fetch(Pet.class, 1));
        assertTrue(null != dao.fetch(Pet.class, 2));
        assertTrue(null != dao.fetch(Pet.class, 3));

        FieldFilter.create(Pet.class, "name|id").run(new Atom() {
            public void run() {
                assertTrue(null != dao.fetch(Pet.class));
            }
        });
    }
View Full Code Here


    ds.setUrl("jdbc:postgresql:test");
    ds.setDefaultAutoCommit(false);
   
    final NutDao dao = new NutDao(ds);
   
    TableName.run(1, new Atom() {
      public void run() {
        Trans.exec(new Atom() {
          public void run() {
            dao.create(Country.class, true);
            System.out.println("------------???");
            dao.insert(Country.make("A"));
            try {
View Full Code Here

        monThread.start();

        out.println("Begin...");
        Stopwatch sw = null;
        try {
            sw = Stopwatch.run(new Atom() {
                public void run() {
                    try {
                        up.parse(req, uc);
                    }
                    catch (UploadException 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

        dao.create(Pet.class, true);
        // 在插入数据中有错误 ...
        final Pet[] pets = Pet.create(10);
        pets[4].setName(Strings.dup('t', 1024));
        try {
            Trans.exec(new Atom() {
                public void run() {
                    dao.fastInsert(pets);
                }
            });
        }
        catch (RuntimeException e) {}
        assertEquals(0, dao.count(Pet.class));
        // 插入后,主动抛出一个错误,看回滚不回滚
        try {
            final Pet[] pets2 = Pet.create(10);
            Trans.exec(new Atom() {
                public void run() {
                    dao.fastInsert(pets2);
                    throw new RuntimeException("I am ok!");
                }
            });
View Full Code Here

    @Test
    public void test_insert_by_fieldfilter() {
        dao.create(Pet.class, true);
        final Pet pet = Pet.create("xb");
        pet.setNickName("xiaobai");
        FieldFilter.create(Pet.class, "^id|name$").run(new Atom() {
            public void run() {
                dao.insert(pet);
            }
        });
        Pet xb = dao.fetch(Pet.class, "xb");
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

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.