Search in sources :

Example 6 with Sql

use of org.eweb4j.orm.sql.Sql in project eweb4j-framework by laiweiwei.

the class TestDeleteSql method testDeleteByOneRelField.

/**
	 * 测试一(多)对一关系的删除sql语句生成
	 * 
	 * @throws Exception
	 */
@Test
public void testDeleteByOneRelField() throws Exception {
    Master master = new Master();
    master.setId(5L);
    pet.setMaster(master);
    String[] fields = { "master" };
    Sql sql = delete.delete(fields)[0];
    Assert.assertEquals("DELETE FROM t_pet WHERE master_id = ?  ;", sql.sql);
    Assert.assertEquals(5l, sql.args.get(0));
}
Also used : Master(test.po.Master) Sql(org.eweb4j.orm.sql.Sql) Test(org.junit.Test)

Example 7 with Sql

use of org.eweb4j.orm.sql.Sql in project eweb4j-framework by laiweiwei.

the class TestDeleteSql method testDeleteByFieldAndValue.

/**
	 * 删除记录,按给定字段、给定值
	 * 
	 * @param clazz
	 * @param fields
	 * @param values
	 * @return
	 */
@Test
public void testDeleteByFieldAndValue() {
    Sql sql = delete.delete(new String[] { "age" }, new String[] { "50" })[0];
    Assert.assertEquals("DELETE FROM t_pet WHERE age = ?  ;", sql.sql);
    Assert.assertEquals("50", sql.args.get(0));
}
Also used : Sql(org.eweb4j.orm.sql.Sql) Test(org.junit.Test)

Example 8 with Sql

use of org.eweb4j.orm.sql.Sql in project eweb4j-framework by laiweiwei.

the class TestDeleteSql method testDeleteWhereByArgs.

/**
	 * 给定条件删除记录,支持?占位符
	 * 
	 * @param clazz
	 * @param condition
	 * @param args
	 * @return
	 */
public void testDeleteWhereByArgs() {
    Sql sql = delete.deleteWhere("name = ?");
    Assert.assertEquals("DELETE FROM t_pet WHERE name = ? ;", sql.sql);
}
Also used : Sql(org.eweb4j.orm.sql.Sql)

Example 9 with Sql

use of org.eweb4j.orm.sql.Sql in project eweb4j-framework by laiweiwei.

the class TestDeleteSql method testDeleteWhere.

/**
	 * 给定条件删除记录
	 * 
	 * @param clazz
	 * @param condition
	 * @return
	 */
public void testDeleteWhere() {
    pet.setName("weiwei");
    Sql sql = delete.deleteWhere("name = ?");
    Assert.assertEquals("DELETE FROM t_pet WHERE name = ? ;", sql.sql);
    Assert.assertEquals("weiwei", sql.args.get(0));
}
Also used : Sql(org.eweb4j.orm.sql.Sql)

Example 10 with Sql

use of org.eweb4j.orm.sql.Sql in project eweb4j-framework by laiweiwei.

the class TestDeleteSql method testMap.

@Test
public void testMap() throws Exception {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("table", "t_pet");
    map.put("idColumn", "id");
    map.put("idValue", 7);
    Pet pet = new Pet();
    DeleteSqlCreator<?> delete = SqlFactory.getDeleteSql(map, pet);
    Sql sql = delete.delete()[0];
    Assert.assertEquals("DELETE FROM t_pet WHERE id = ?  ;", sql.sql);
    Assert.assertEquals(7, sql.args.get(0));
}
Also used : HashMap(java.util.HashMap) Pet(test.po.Pet) Sql(org.eweb4j.orm.sql.Sql) Test(org.junit.Test)

Aggregations

Sql (org.eweb4j.orm.sql.Sql)28 Connection (java.sql.Connection)13 DAOException (org.eweb4j.orm.dao.DAOException)13 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)6 Master (test.po.Master)4 HashMap (java.util.HashMap)3 Pet (test.po.Pet)3