summaryrefslogtreecommitdiffstats
path: root/java/MyMyBatis/src/Main.java
blob: deb274f43207e3eb3eab4501a52d63c024e990ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package ch.asynk;

import java.util.List;

public class Main
{
    private static void failIf(boolean fail, String msg)
    {
        if (fail) {
            System.err.println("FAIL " + msg);
            System.exit(1);
        }
    }

    public static void main(String [] args )
    {
        try {
            ModelDAO.getSqlConnection().runScript("create.sql");
        } catch (java.io.IOException e) {
            System.err.println(e.getMessage());
        }

        ModelDAO dao = ModelDAO.getInstance();
        Model m;
        List<Model> models;

        int count = dao.count();
        failIf(count != 2, "count()");
        System.out.println("count  : " + count);
        models = dao.select();
        count = models.size();
        failIf(count != 2, "select()");
        System.out.println("select : ");
        for (Model _m : models) System.out.println(" - " +_m.toString());

        m = dao.selectOne(2);
        failIf(m == null , "selectOne()");
        System.out.println("selectOne : " + m.toString());
        System.out.println("update ...");
        m.setName("adios");
        m.save();
        m = dao.selectOne(2);
        failIf(m == null , "selectOne()");
        failIf(!m.getName().equals("adios") , "selectOne()");
        System.out.println("selectOne : " + m.toString());
        count = m.delete();
        failIf(count != 1, "delete()");
        System.out.println("delete : " + count);
        count = dao.count();
        failIf(count != 1, "count()");
        System.out.println("count  : " + count);
        System.out.println("insert ...");
        m = new Model("HoMySatan");
        m.save();
        failIf(count != 1, "insert()");
        count = dao.count();
        failIf(count != 2, "count()");
        System.out.println("count  : " + count);
        System.out.println("select : ");
        models = dao.select();
        count = models.size();
        failIf(count != 2, "select()");
        for (Model _m : models) System.out.println(" - " +_m.toString());
    }
}