Package org.nutz.dao.sql

Examples of org.nutz.dao.sql.Sql


    }

    @Test
    public void run_2_sqls_with_error() {
        assertEquals(0, dao.count(Pet.class));
        Sql sql1 = Sqls.create("INSERT INTO t_pet (name) VALUES ('A')");
        Sql sql2 = Sqls.create("INSERT INTO t_pet (nocol) VALUES ('B')");
        try {
            dao.execute(sql1, sql2);
            fail();
        }
        catch (DaoException e) {}
View Full Code Here


                            .add("nickName",
                                 "Time=" + System.currentTimeMillis()));
        }
        Pager pager = dao.createPager(5, 5);
        pager.setRecordCount(dao.count(Pet.class));
        Sql sql = Sqls.queryEntity("select * from t_pet");
        sql.setEntity(dao.getEntity(Pet.class));
        sql.setPager(pager);
        dao.execute(sql);

        List<Pet> pets = sql.getList(Pet.class);
        assertNotNull(pets);
        assertEquals(5, pets.size());
        assertEquals("record20", pets.get(0).getName());
        assertEquals("record21", pets.get(1).getName());
        assertEquals("record22", pets.get(2).getName());
View Full Code Here

    }

    @Test
    public void clear_links() {
        dao.create(Pet.class, true);
        Sql sql1 = Sqls.create("INSERT INTO t_pet (name) VALUES ('A')");
        Sql sql2 = Sqls.create("INSERT INTO t_pet (nocol) VALUES ('B')");
        try {
            dao.execute(sql1, sql2);
            fail();
        }
        catch (DaoException e) {}
View Full Code Here

      return; // Only test for h2 now
    dao.create(Pet.class, true);
    dao.insert(Pet.create("wendal"));
    dao.execute(Sqls.create("CALL SELECT MAX(ID) FROM t_PET"));

    Sql sql = Sqls.fetchInt("CALL SELECT MAX(ID) FROM t_PET");
    dao.execute(sql);
    assertEquals(1, sql.getInt());

    sql = Sqls.fetchInt("CALL 15*25");
    dao.execute(sql);
    assertEquals(15 * 25, sql.getInt());
  }
View Full Code Here

    dao.create(Pet.class, true);
    dao.insert(Pet.create("wendal"));
    dao.execute(Sqls.create("DROP PROCEDURE IF EXISTS proc_pet_getCount"));

    dao.execute(Sqls.create("CREATE PROCEDURE proc_pet_getCount()\nBEGIN\n\tSELECT name FROM t_pet;\nEND"));
    Sql sql = Sqls.fetchString("CALL proc_pet_getCount()"); // 单一结果集,且没有输入输出参数
    dao.execute(sql);
    assertEquals("wendal", sql.getString());
  }
View Full Code Here

    dao.create(Pet.class, true);
    dao.insert(Pet.create("wendal"));
    dao.execute(Sqls.create("DROP PROCEDURE IF EXISTS proc_pet_fetch"));

    dao.execute(Sqls.create("CREATE PROCEDURE proc_pet_fetch(IN nm varchar(1024))\nBEGIN\n\tSELECT * FROM t_pet where name=nm;\nEND"));
    Sql sql = Sqls.fetchEntity("CALL proc_pet_fetch(@nm)");
    sql.setEntity(dao.getEntity(Pet.class));
    sql.params().set("nm", "wendal");
    dao.execute(sql);
   
    Pet pet = sql.getObject(Pet.class);
    assertNotNull(pet);
    assertEquals("wendal", pet.getName());
  }
View Full Code Here

                pet.setNickName("AA_" + pet.getName().toUpperCase());
                dao.update(pet);
            }
        });
        Entity<Pet> en = dao.getEntity(Pet.class);
        Sql sql = Sqls.queryRecord("SELECT * FROM t_pet");
        dao.execute(sql);
        List<Record> recs = sql.getList(Record.class);
        Pet[] pets = new Pet[recs.size()];
        int i = 0;
        for (Record rec : recs)
            pets[i++] = rec.toEntity(en);

View Full Code Here

    public void createTableTimestampFieldDefaultNullInMySQL() throws Exception {
        boolean isMySql = dao.meta().isMySql();
        // 这个仅仅测试MySQL数据库
        if (isMySql) {
            dao.create(TableWithTimestampInMySql.class, true);
            Sql descTable = Sqls.create(DESC_TABLE_SQL);
            descTable.params().set("tableName", "t_ts");
            descTable.setCallback(new SqlCallback() {
                public Object invoke(Connection conn, ResultSet rs, Sql sql) throws SQLException {
                    boolean ts1 = false;
                    boolean ts2 = false;
                    boolean ts3 = false;
                    boolean ts4 = false;
                    while (rs.next()) {
                        String columnName = rs.getString(1);
                        String isNullable = rs.getString(2);
                        String defaultValue = rs.getString(3);
                        String extra = rs.getString(4);
                        if ("ts1".equals(columnName)) {
                            if ((null == defaultValue || "NULL".equalsIgnoreCase(defaultValue))
                                && "YES".equalsIgnoreCase(isNullable)) {
                                ts1 = true;
                            }
                        }
                        if ("ts2".equals(columnName)) {
                            if (null != defaultValue
                                && "0000-00-00 00:00:00".equals(defaultValue)
                                && "YES".equalsIgnoreCase(isNullable)) {
                                ts2 = true;
                            }
                        }
                        if ("ts3".equals(columnName)) {
                            if (null != defaultValue
                                && "0000-00-00 00:00:00".equals(defaultValue)
                                && "NO".equalsIgnoreCase(isNullable)) {
                                ts3 = true;
                            }
                        }
                        if ("ts4".equals(columnName)) {
                            if (null != defaultValue
                                && "CURRENT_TIMESTAMP".equalsIgnoreCase(defaultValue)
                                && "NO".equalsIgnoreCase(isNullable)
                                && "ON UPDATE CURRENT_TIMESTAMP".equalsIgnoreCase(extra)) {
                                ts4 = true;
                            }
                        }
                    }
                    return ts1 && ts2 && ts3 && ts4;
                }
            });
            dao.execute(descTable);
            boolean isTrue = descTable.getObject(Boolean.class);
            Assert.assertTrue(isTrue);
        }
    }
View Full Code Here

    dao.insert(new XPet());
   
    assertEquals(1, dao.count(XPet.class));
    assertNotNull(dao.fetch(XPet.class));
   
    Sql sql = Sqls.fetchEntity("select * from t_xpet");
    sql.setEntity(dao.getEntity(XPet.class));
    dao.execute(sql);
    assertNotNull(sql.getObject(XPet.class));
    assertNull(sql.getObject(XPet.class).getOtherTime());
  }
View Full Code Here

        boolean isMySql = dao.meta().isMySql();
        // 这个仅仅测试MySQL数据库
        if (isMySql) {
            dao.create(TableWithComment.class, true);
            // 表注释
            Sql findTableComment = Sqls.create(FIND_TABLE_COMMENT_MYSQL);
            findTableComment.params().set("tableName", "t_twc");
            findTableComment.setCallback(Sqls.callback.str());
            dao.execute(findTableComment);
            String tableComment = findTableComment.getString();
            Assert.assertTrue(!Strings.isBlank(tableComment) && "测试表".equals(tableComment));
            // 字段注释
            Sql findIdComment = Sqls.create(FIND_COLUMN_COMMENT_MYSQL);
            findIdComment.params().set("tableName", "t_twc").set("columnName", "id");
            findIdComment.setCallback(Sqls.callback.str());
            dao.execute(findIdComment);
            String idComment = findIdComment.getString();
            Assert.assertTrue(!Strings.isBlank(idComment) && "唯一主键".equals(idComment));

            Sql findNameComment = Sqls.create(FIND_COLUMN_COMMENT_MYSQL);
            findNameComment.params().set("tableName", "t_twc").set("columnName", "nm");
            findNameComment.setCallback(Sqls.callback.str());
            dao.execute(findNameComment);
            String nameComment = findNameComment.getString();
            Assert.assertTrue(!Strings.isBlank(nameComment) && "name".equals(nameComment));

            Sql findNumComment = Sqls.create(FIND_COLUMN_COMMENT_MYSQL);
            findNumComment.params().set("tableName", "t_twc").set("columnName", "num");
            findNumComment.setCallback(Sqls.callback.str());
            dao.execute(findNumComment);
            String numComment = findNumComment.getString();
            Assert.assertTrue(Strings.isBlank(numComment));
        }
    }
View Full Code Here

TOP

Related Classes of org.nutz.dao.sql.Sql

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.